Re: [PATCH 2/2 v2] Driver core: reduce duplicated code

From: Eric Miao
Date: Mon Jun 28 2010 - 01:28:11 EST


2010/6/28 Uwe Kleine-KÃnig <u.kleine-koenig@xxxxxxxxxxxxxx>:
> Hi Eric,
>
> On Mon, Jun 28, 2010 at 12:55:45PM +0800, Eric Miao wrote:
>> I suggest you to have a look into arch/arm/mach-mmp/devices.c and
>> arch/arm/mach-mmp/pxa{168,910}.c as well as
>> arch/arm/mach-mmp/include/mach/pxa{168,910}.h, maybe we can find
>> some common practice.
> I think I like this approach in general, I already thought about not
> passing all parameters as function/macro arguments, too. ÂBut maybe this
> becomes too excessive for imx as I would need too many of these device
> desc for the different imx variants?!
>
> Anyhow a few things I thought when looking in the files you suggested:
>
> Â- Why not use an array for all uart devdescs, maybe the code for
> Â pxa168_add_uart could become a bit smaller then?:
>
> Â Â Â Âextern struct pxa_device_desc pxa168_device_uart[2];
> Â Â Â Â...
> Â Â Â Âstatic inline int pxa168_add_uart(int id)
> Â Â Â Â{
> Â Â Â Â Â Â Â Âstruct pxa_device_desc *d = pxa168_device_uart + id;
>
> Â Â Â Â Â Â Â Âif (id < 0 || id > 2)
> Â Â Â Â Â Â Â Â Â Â Â Âreturn -EINVAL;
>
> Â Â Â Â Â Â Â Âreturn pxa_register_device(d, NULL, 0);
> Â Â Â Â}
>
> Â (Ditto for the other types obviously.)

That's a good suggestion, yet it came that way for two reasons:

1. the initial naming mess, uart0 was later renamed to uart1, e.g.
2. and the restrictions of PXA{168,910}_DEVICE() macros, these
macros are handy to simplify the definition, but may require fancy
tricks to make it support array

>
> Â- shouldn't all these pxa_device_descs and pxa168_add_$device functions
> Â be __initdata and __init?
>

pxa{168,910}_add_device() are actually 'static inline' so my assumption
is they will be inlined when referenced, otherwise won't occupy any code
space. The *_descs, however, they are __initdata if you look into the
definitions of PXA{168,910}_DEVICES

> Â- pxa_register_device is better than my add_resndata function in (at
> Â least) one aspect as it sets coherent_dma_mask, too. ÂThis is
> Â something I missed when trying to add mxc-mmc (IIRC) devices.
>
> Thanks
> Uwe
>
> --
> Pengutronix e.K.              | Uwe Kleine-KÃnig      Â|
> Industrial Linux Solutions         | http://www.pengutronix.de/ Â|
>
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/