Re: [PATCH] Topcliff: Update PCH_SPI driver to 2.6.35

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Grant Likely
Date: Friday, August 13, 2010 - 11:49 pm

2010/8/10 Masayuki Ohtak <masa-korg@dsn.okisemi.com>:

Hi Masayuki.  Thanks for the patch.  The driver is mostly structured
well and looks fairly good.  However, there are quite a few stylistic
issues that should be easy to clean up, and a few technical concerns.
Comments below.

BTW, please make sure patches get sent out as plain-text, not html formatted.


What is IOH and abbreviation for?


Being required to specific this at kernel config time isn't
multiplatform friendly.  Can the driver detect the number of busses at
runtime.


Put config PCH_SPI above PCH_SPI_PLATFORM_DEVICE and make
PCH_SPI_PLATFORM_DEVICE depend on PCH_SPI.  (In fact, since
PCH_SPI_PLATFORM_DEVICE is always yes when PCH_SPI is selected, then
you probably don't need two configuration signals).


No need to use pch_spi-objs when there is only one .o file.  Just name
the .c file what you want the resulting kernel module to be named.
Also, please rename the modules to "spi_pch_platform_device.o" and
"spi_pch.o" (I'm enforcing all new spi drivers to start with the
prefix "spi_").

Finally, do pch_spi_platform_devices.o and pch_spi_main.o really need
to be in separate modules?


It is helpful to have a one line description of what this file is for
in at the top of the header comment block.

[...]

Because the macro has side-effects, I'd prefer to see static inlines
used here with an all lowercase name.


Are these statics really necessary?  I think the callback can be
removed (see my comment below).  The mutex should probably be a member
of the pch_spi_data structure.  Getting rid of the static symbols will
make it easier if the driver ever needs to support multiple instances
of the device.


Is it possible for more than one of these interrupt bits to be set at
the same time?  If so, then this switch() statement won't always work.


nit: use lowercase for variable names.


Wow, the nesting on this function is very deep, and hard to follow.
Candidate for refactoring?


This trivial function is used exactly once in the probe routine.  Just
set the variable in-place.  In fact, this doesn't need to be a
callback at all because it is *always* set to pch_spi_callback.
Removing it will make the driver simpler.


There are a lot of these if/else blocks which call
PCH_{SET,CLR}_BITMSK().  The code could be simplified with a helper
function that implements the two paths.  Something like
pch_spi_clrsetbits() perhaps.



If the requested speed is too fast, then the maximum bus speed should
be used instead.


Optimization note; by coding it this way, the (PCH_8_BPW == *bpw) test
is being performed on every iteration through the loop.  If you had
separate iterators for 8 and 16 bit transfer, the code will be faster.


Nit: It would be easier to read if the comment blocks were tidied up.
There should be a space between /* and the first word, and some
comments, like this one, will fit on a single line.


When splitting lines in the middle of an argument list, please indent
up to the same level as the first argument.


if (p_data->pcur_trans->rx_buf)
	return;

That reduces the indentation on the rest of the function by one level
and makes it easier to read and understand.


Same comment on optimization.


The complete callback cannot be called while still holding the spinlock.


Put a return statement here.  It will eliminate the else { }
indentation below; again improving readability.


nit: for loop index variables should be reused.  Don't use a new index
for every single for() loop.


kzalloc()


spi_master_num isn't used except for the error path, and it always has
the same value as 'j'.  Get it out of the loop initializer!  :-)  It
can be set in the error path.


You probably want -1 here so that the spi layer dynamically assigns an
spi bus number.


Unnecessary line break.  There are a lot of these in this driver.


The above 7 lines can be dropped when the code is changed to use
kzalloc().  kzalloc() clears the allocated memory.


Remove the (void *) cast.  It should not be necessary.


if (!p_board_dat) {
	dev_err(...);
	return;
}


Ditto here; return -EFAULT;


Another very deeply indented function.


This file is misnamed; these aren't platform_devices, they are spi_devices.


int rc = -1;


How about when the module is removed?

This particular module (not the rest of the driver though) is really
rather a hack.  It seems like you need a method for creating spidev
devices from userspace at runtime, or having a method for specifying
spi device from the kernel command line.  Using a flattened device
tree fragment would work as well.

g.


-- 
Grant Likely, B.Sc., P.Eng.
Secret Lab Technologies Ltd.
--
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
Re: [PATCH] Topcliff: Update PCH_SPI driver to 2.6.35, Grant Likely, (Fri Aug 13, 11:49 pm)
Re: [PATCH] Topcliff: Update PCH_SPI driver to 2.6.35, Masayuki Ohtake, (Tue Aug 17, 12:34 am)
Re: [PATCH] Topcliff: Update PCH_SPI driver to 2.6.35, Linus Walleij, (Thu Aug 19, 12:31 am)
Re: [PATCH] Topcliff: Update PCH_SPI driver to 2.6.35, Masayuki Ohtake, (Thu Aug 19, 7:20 pm)
Re: [PATCH] Topcliff: Update PCH_SPI driver to 2.6.35, Masayuki Ohtake, (Fri Aug 27, 6:30 am)
Re: [PATCH] Topcliff: Update PCH_SPI driver to 2.6.35, Grant Likely, (Fri Aug 27, 10:15 am)
Re: [PATCH] Topcliff: Update PCH_SPI driver to 2.6.35, Masayuki Ohtake, (Mon Aug 30, 11:55 pm)