2010-01-10 16:59:54

by Németh Márton

[permalink] [raw]
Subject: [PATCH 3/3] serial: make PCI device id constant

From: Márton Németh <[email protected]>

The id_table field of the struct pci_driver is constant in <linux/pci.h>
so it is worth to make initialization data also constant.

The semantic match that finds this kind of pattern is as follows:
(http://coccinelle.lip6.fr/)

// <smpl>
@r@
disable decl_init,const_decl_init;
identifier I1, I2, x;
@@
struct I1 {
...
const struct I2 *x;
...
};
@s@
identifier r.I1, y;
identifier r.x, E;
@@
struct I1 y = {
.x = E,
};
@c@
identifier r.I2;
identifier s.E;
@@
const struct I2 E[] = ... ;
@depends on !c@
identifier r.I2;
identifier s.E;
@@
+ const
struct I2 E[] = ...;
// </smpl>

Signed-off-by: Márton Németh <[email protected]>
Cc: Julia Lawall <[email protected]>
Cc: [email protected]
---
diff -u -p a/drivers/serial/8250_pci.c b/drivers/serial/8250_pci.c
--- a/drivers/serial/8250_pci.c 2009-12-03 04:51:21.000000000 +0100
+++ b/drivers/serial/8250_pci.c 2010-01-08 18:40:05.000000000 +0100
@@ -2567,7 +2567,7 @@ static int pciserial_resume_one(struct p
}
#endif

-static struct pci_device_id serial_pci_tbl[] = {
+static const struct pci_device_id serial_pci_tbl[] = {
/* Advantech use PCI_DEVICE_ID_ADVANTECH_PCI3620 (0x3620) as 'PCI_SUBVENDOR_ID' */
{ PCI_VENDOR_ID_ADVANTECH, PCI_DEVICE_ID_ADVANTECH_PCI3620,
PCI_DEVICE_ID_ADVANTECH_PCI3620, 0x0001, 0, 0,
diff -u -p a/drivers/serial/jsm/jsm_driver.c b/drivers/serial/jsm/jsm_driver.c
--- a/drivers/serial/jsm/jsm_driver.c 2010-01-07 19:08:45.000000000 +0100
+++ b/drivers/serial/jsm/jsm_driver.c 2010-01-08 18:41:09.000000000 +0100
@@ -218,7 +218,7 @@ static void __devexit jsm_remove_one(str
kfree(brd);
}

-static struct pci_device_id jsm_pci_tbl[] = {
+static const struct pci_device_id jsm_pci_tbl[] = {
{ PCI_DEVICE(PCI_VENDOR_ID_DIGI, PCI_DEVICE_ID_NEO_2DB9), 0, 0, 0 },
{ PCI_DEVICE(PCI_VENDOR_ID_DIGI, PCI_DEVICE_ID_NEO_2DB9PRI), 0, 0, 1 },
{ PCI_DEVICE(PCI_VENDOR_ID_DIGI, PCI_DEVICE_ID_NEO_2RJ45), 0, 0, 2 },


2010-01-10 17:51:46

by Michał Mirosław

[permalink] [raw]
Subject: Re: [PATCH 3/3] serial: make PCI device id constant

2010/1/10 N?meth M?rton <[email protected]>:
> From: M?rton N?meth <[email protected]>
>
> The id_table field of the struct pci_driver is constant in <linux/pci.h>
> so it is worth to make initialization data also constant.
[...]
> diff -u -p a/drivers/serial/8250_pci.c b/drivers/serial/8250_pci.c
> --- a/drivers/serial/8250_pci.c 2009-12-03 04:51:21.000000000 +0100
> +++ b/drivers/serial/8250_pci.c 2010-01-08 18:40:05.000000000 +0100
> @@ -2567,7 +2567,7 @@ static int pciserial_resume_one(struct p
> ?}
> ?#endif
>
> -static struct pci_device_id serial_pci_tbl[] = {
> +static const struct pci_device_id serial_pci_tbl[] = {
> ? ? ? ?/* Advantech use PCI_DEVICE_ID_ADVANTECH_PCI3620 (0x3620) as 'PCI_SUBVENDOR_ID' */
> ? ? ? ?{ ? ? ? PCI_VENDOR_ID_ADVANTECH, PCI_DEVICE_ID_ADVANTECH_PCI3620,
> ? ? ? ? ? ? ? ?PCI_DEVICE_ID_ADVANTECH_PCI3620, 0x0001, 0, 0,
[...]

There was similar patch sent to netdev couple days ago. For PCI
devices it used DEFINE_PCI_DEVICE_TABLE() like this:

static DEFINE_PCI_DEVICE_TABLE(serial_pci_tbl) = {

so that the ID data went to the proper .ko section.

Best Regards,
Micha? Miros?aw

2010-01-10 19:43:57

by Németh Márton

[permalink] [raw]
Subject: Re: [PATCH 3/3] serial: make PCI device id constant

Micha? Miros?aw wrote:
> 2010/1/10 N?meth M?rton <[email protected]>:
>> From: M?rton N?meth <[email protected]>
>>
>> The id_table field of the struct pci_driver is constant in <linux/pci.h>
>> so it is worth to make initialization data also constant.
> [...]
>> diff -u -p a/drivers/serial/8250_pci.c b/drivers/serial/8250_pci.c
>> --- a/drivers/serial/8250_pci.c 2009-12-03 04:51:21.000000000 +0100
>> +++ b/drivers/serial/8250_pci.c 2010-01-08 18:40:05.000000000 +0100
>> @@ -2567,7 +2567,7 @@ static int pciserial_resume_one(struct p
>> }
>> #endif
>>
>> -static struct pci_device_id serial_pci_tbl[] = {
>> +static const struct pci_device_id serial_pci_tbl[] = {
>> /* Advantech use PCI_DEVICE_ID_ADVANTECH_PCI3620 (0x3620) as 'PCI_SUBVENDOR_ID' */
>> { PCI_VENDOR_ID_ADVANTECH, PCI_DEVICE_ID_ADVANTECH_PCI3620,
>> PCI_DEVICE_ID_ADVANTECH_PCI3620, 0x0001, 0, 0,
> [...]
>
> There was similar patch sent to netdev couple days ago. For PCI
> devices it used DEFINE_PCI_DEVICE_TABLE() like this:
>
> static DEFINE_PCI_DEVICE_TABLE(serial_pci_tbl) = {
>
> so that the ID data went to the proper .ko section.

Thanks for the feedback. The DEFINE_PCI_DEVICE_TABLE() is also recommended
by Documentation/PCI/pci.txt .

Regads,

M?rton N?meth