PCI: rename alloc_pci_dev() to pci_alloc_dev()
Subsystems (7)
PATCH 2/3 PCI: rename alloc_pci_dev() to pci_alloc_dev()
Quoted 1 line
From
a3135f4a814ec2faba007f030ca96ea2297484efMon Sep 17 00:00:00 2001
From: Gu Zheng <[email protected]>
Date: Thu, 18 Apr 2013 17:27:40 +0900
Subject: [PATCH 2/3] PCI: rename alloc_pci_dev() to pci_alloc_dev()
Rename alloc_pci_dev() to pci_alloc_dev() to make the name style the same as pci_alloc_bus(), pci_destroy_dev().
--- arch/powerpc/kernel/pci_of_scan.c | 2 +- drivers/char/agp/alpha-agp.c | 2 +- drivers/char/agp/parisc-agp.c | 2 +- drivers/pci/iov.c | 2 +- drivers/pci/probe.c | 6 +++--- drivers/scsi/megaraid.c | 2 +- include/linux/pci.h | 2 +- 7 files changed, 9 insertions(+), 9 deletions(-)
arch/powerpc/kernel/pci_of_scan.c +1 -1
@@ -128,7 +128,7 @@ struct pci_dev *of_create_pci_dev(struct device_node *node,const char *type;struct pci_slot *slot; - dev =alloc_pci_dev (); + dev =pci_alloc_dev ();if (!dev)return NULL ; type =of_get_property (node,"device_type" ,NULL );
drivers/char/agp/alpha-agp.c +1 -1
@@ -174,7 +174,7 @@ alpha_core_agp_setup(void)/* * Build a fake pci_dev struct */ - pdev =alloc_pci_dev (); + pdev =pci_alloc_dev ();if (!pdev)return -ENOMEM ; pdev->vendor =0xffff ;
drivers/char/agp/parisc-agp.c +1 -1
@@ -333,7 +333,7 @@ parisc_agp_setup(void __iomem *ioc_hpa, void __iomem *lba_hpa)struct agp_bridge_data *bridge;int error =0 ; - fake_bridge_dev =alloc_pci_dev (); + fake_bridge_dev =pci_alloc_dev ();if (!fake_bridge_dev) { error = -ENOMEM ; goto fail;
drivers/pci/iov.c +1 -1
@@ -77,7 +77,7 @@ static int virtfn_add(struct pci_dev *dev, int id, int reset)struct resource *res;struct pci_sriov *iov = dev->sriov; - virtfn =alloc_pci_dev (); + virtfn =pci_alloc_dev ();if (!virtfn)return -ENOMEM ;
drivers/pci/probe.c +3 -3
@@ -1199,7 +1199,7 @@ static void pci_release_bus_bridge_dev(struct device *dev)kfree (bridge); } -struct pci_dev *alloc_pci_dev (void ) +struct pci_dev *pci_alloc_dev (void ) {struct pci_dev *dev;
@@ -1211,7 +1211,7 @@ struct pci_dev *alloc_pci_dev(void)return dev; } -EXPORT_SYMBOL (alloc_pci_dev); +EXPORT_SYMBOL (pci_alloc_dev);bool pci_bus_read_dev_vendor_id (struct pci_bus *bus,int devfn,u32 *l,int crs_timeout)
@@ -1261,7 +1261,7 @@ static struct pci_dev *pci_scan_device(struct pci_bus *bus, int devfn)if (!pci_bus_read_dev_vendor_id (bus, devfn, &l,60 *1000 ))return NULL ; - dev =alloc_pci_dev (); + dev =pci_alloc_dev ();if (!dev)return NULL ;
drivers/scsi/megaraid.c +1 -1
@@ -2025,7 +2025,7 @@ megaraid_abort_and_reset(adapter_t *adapter, Scsi_Cmnd *cmd, int aor)static inline int make_local_pdev (adapter_t *adapter,struct pci_dev **pdev) { - *pdev =alloc_pci_dev (); + *pdev =pci_alloc_dev ();if ( *pdev ==NULL )return -1 ;
include/linux/pci.h +1 -1
@@ -348,7 +348,7 @@ static inline struct pci_dev *pci_physfn(struct pci_dev *dev)return dev; } -extern struct pci_dev *alloc_pci_dev (void ); +extern struct pci_dev *pci_alloc_dev (void );#define to_pci_dev (n) container_of(n, struct pci_dev, dev)#define for_each_pci_dev (d) while ((d = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, d)) != NULL)
Signature · 1 line
1.7.1
Bjorn Helgaas
maintainerQuoted 86 lines · Gu Zheng
From
a3135f4a814ec2faba007f030ca96ea2297484efMon Sep 17 00:00:00 2001
From: Gu Zheng <[email protected]>
Date: Thu, 18 Apr 2013 17:27:40 +0900
Subject: [PATCH 2/3] PCI: renamealloc_pci_dev()topci_alloc_dev()Rename
alloc_pci_dev()topci_alloc_dev()to make the name style the same aspci_alloc_bus(),pci_destroy_dev().Signed-off-by Gu Zheng <[email protected]>Reviewed-by Li Guang <[email protected]>--- arch/powerpc/kernel/pci_of_scan.c | 2 +- drivers/char/agp/alpha-agp.c | 2 +- drivers/char/agp/parisc-agp.c | 2 +- drivers/pci/iov.c | 2 +- drivers/pci/probe.c | 6 +++--- drivers/scsi/megaraid.c | 2 +- include/linux/pci.h | 2 +- 7 files changed, 9 insertions(+), 9 deletions(-)arch/powerpc/kernel/pci_of_scan.c +1
-1@@ -128,7 +128,7 @@ struct pci_dev *of_create_pci_dev(struct device_node *node,const char *type;struct pci_slot *slot; - dev =alloc_pci_dev (); + dev =pci_alloc_dev ();if (!dev)return NULL ; type =of_get_property (node,"device_type" ,NULL );drivers/char/agp/alpha-agp.c +1
-1@@ -174,7 +174,7 @@ alpha_core_agp_setup(void)/* * Build a fake pci_dev struct */ - pdev =alloc_pci_dev (); + pdev =pci_alloc_dev ();if (!pdev)return -ENOMEM ; pdev->vendor =0xffff ;drivers/char/agp/parisc-agp.c +1
-1@@ -333,7 +333,7 @@ parisc_agp_setup(void __iomem *ioc_hpa, void __iomem *lba_hpa)struct agp_bridge_data *bridge;int error =0 ; - fake_bridge_dev =alloc_pci_dev (); + fake_bridge_dev =pci_alloc_dev ();if (!fake_bridge_dev) { error = -ENOMEM ; goto fail;drivers/pci/iov.c +1
-1@@ -77,7 +77,7 @@ static int virtfn_add(struct pci_dev *dev, int id, int reset)struct resource *res;struct pci_sriov *iov = dev->sriov; - virtfn =alloc_pci_dev (); + virtfn =pci_alloc_dev ();if (!virtfn)return -ENOMEM ;drivers/pci/probe.c +1
-1@@ -1199,7 +1199,7 @@ static void pci_release_bus_bridge_dev(struct device *dev)kfree (bridge); } -struct pci_dev *alloc_pci_dev (void ) +struct pci_dev *pci_alloc_dev (void ) {struct pci_dev *dev;
drivers/pci/probe.c struct pci_dev *alloc_pci_dev(void) · line 1214
Quoted 5 lines
drivers/pci/probe.c +1
-1@@ -1211,7 +1211,7 @@ struct pci_dev *alloc_pci_dev(void)return dev; } -EXPORT_SYMBOL (alloc_pci_dev); +EXPORT_SYMBOL (pci_alloc_dev);
I like these patches a lot. But I think we have some logistical issues to work out.
Since alloc_pci_dev() is exported, there may be out-of-tree modules that use it, so I don't want to simply remove alloc_pci_dev() completely. I think it would be better to keep it for a while but mark it as __deprecated.
You can introduce a new pci_alloc_dev() here, and since it's a new interface, I think you might as well make it take a "struct pci_bus *" and acquire the reference from the beginning.
I think you could then make the final patch be the only one that touches powerpc, agp, megaraid, etc., to convert them from alloc_pci_dev(void) to pci_alloc_dev(bus).
Bjorn
Quoted 45 lines
drivers/pci/probe.c +1
-1bool pci_bus_read_dev_vendor_id (struct pci_bus *bus,int devfn,u32 *l,int crs_timeout)@@ -1261,7 +1261,7 @@ static struct pci_dev *pci_scan_device(struct pci_bus *bus, int devfn)if (!pci_bus_read_dev_vendor_id (bus, devfn, &l,60 *1000 ))return NULL ; - dev =alloc_pci_dev (); + dev =pci_alloc_dev ();if (!dev)return NULL ;drivers/scsi/megaraid.c +1
-1@@ -2025,7 +2025,7 @@ megaraid_abort_and_reset(adapter_t *adapter, Scsi_Cmnd *cmd, int aor)static inline int make_local_pdev (adapter_t *adapter,struct pci_dev **pdev) { - *pdev =alloc_pci_dev (); + *pdev =pci_alloc_dev ();if ( *pdev ==NULL )return -1 ;include/linux/pci.h +1
-2@@ -348,7 +348,7 @@ static inline struct pci_dev *pci_physfn(struct pci_dev *dev)return dev; } -extern struct pci_dev *alloc_pci_dev (void ); +extern struct pci_dev *pci_alloc_dev (void );#define to_pci_dev (n) container_of(n, struct pci_dev, dev)#define for_each_pci_dev (d) while ((d = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, d)) != NULL) --1.7.1
--
To unsubscribe from this list: send the line "unsubscribe linux-pci" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 102 lines · Bjorn Helgaas
Quoted 86 lines · Gu Zheng
From
a3135f4a814ec2faba007f030ca96ea2297484efMon Sep 17 00:00:00 2001
From: Gu Zheng <[email protected]>
Date: Thu, 18 Apr 2013 17:27:40 +0900
Subject: [PATCH 2/3] PCI: renamealloc_pci_dev()topci_alloc_dev()Rename
alloc_pci_dev()topci_alloc_dev()to make the name style the same aspci_alloc_bus(),pci_destroy_dev().Signed-off-by Gu Zheng <[email protected]>Reviewed-by Li Guang <[email protected]>--- arch/powerpc/kernel/pci_of_scan.c | 2 +- drivers/char/agp/alpha-agp.c | 2 +- drivers/char/agp/parisc-agp.c | 2 +- drivers/pci/iov.c | 2 +- drivers/pci/probe.c | 6 +++--- drivers/scsi/megaraid.c | 2 +- include/linux/pci.h | 2 +- 7 files changed, 9 insertions(+), 9 deletions(-)arch/powerpc/kernel/pci_of_scan.c +1
-1@@ -128,7 +128,7 @@ struct pci_dev *of_create_pci_dev(struct device_node *node,const char *type;struct pci_slot *slot; - dev =alloc_pci_dev (); + dev =pci_alloc_dev ();if (!dev)return NULL ; type =of_get_property (node,"device_type" ,NULL );drivers/char/agp/alpha-agp.c +1
-1@@ -174,7 +174,7 @@ alpha_core_agp_setup(void)/* * Build a fake pci_dev struct */ - pdev =alloc_pci_dev (); + pdev =pci_alloc_dev ();if (!pdev)return -ENOMEM ; pdev->vendor =0xffff ;drivers/char/agp/parisc-agp.c +1
-1@@ -333,7 +333,7 @@ parisc_agp_setup(void __iomem *ioc_hpa, void __iomem *lba_hpa)struct agp_bridge_data *bridge;int error =0 ; - fake_bridge_dev =alloc_pci_dev (); + fake_bridge_dev =pci_alloc_dev ();if (!fake_bridge_dev) { error = -ENOMEM ; goto fail;drivers/pci/iov.c +1
-1@@ -77,7 +77,7 @@ static int virtfn_add(struct pci_dev *dev, int id, int reset)struct resource *res;struct pci_sriov *iov = dev->sriov; - virtfn =alloc_pci_dev (); + virtfn =pci_alloc_dev ();if (!virtfn)return -ENOMEM ;drivers/pci/probe.c +1
-1@@ -1199,7 +1199,7 @@ static void pci_release_bus_bridge_dev(struct device *dev)kfree (bridge); } -struct pci_dev *alloc_pci_dev (void ) +struct pci_dev *pci_alloc_dev (void ) {struct pci_dev *dev;drivers/pci/probe.c struct pci_dev *alloc_pci_dev(void) · line 1214
Quoted 5 lines
drivers/pci/probe.c +1
-1@@ -1211,7 +1211,7 @@ struct pci_dev *alloc_pci_dev(void)return dev; } -EXPORT_SYMBOL (alloc_pci_dev); +EXPORT_SYMBOL (pci_alloc_dev);I like these patches a lot. But I think we have some logistical issues to work out.
Since
alloc_pci_dev()is exported, there may be out-of-tree modules that use it, so I don't want to simply removealloc_pci_dev()completely. I think it would be better to keep it for a while but mark it as__deprecated.
Quoted 7 lines
You can introduce a new
pci_alloc_dev()here, and since it's a new interface, I think you might as well make it take a "structpci_bus*" and acquire the reference from the beginning.I think you could then make the final patch be the only one that touches powerpc, agp, megaraid, etc., to convert them from
alloc_pci_dev(void)topci_alloc_dev(bus).
Hi Bjorn,
Thanks for your suggestions very much, and I'll send out a new version soon.
Best regards,
Gu
Quoted 49 lines
Bjorn
Quoted 45 lines
drivers/pci/probe.c +1
-1bool pci_bus_read_dev_vendor_id (struct pci_bus *bus,int devfn,u32 *l,int crs_timeout)@@ -1261,7 +1261,7 @@ static struct pci_dev *pci_scan_device(struct pci_bus *bus, int devfn)if (!pci_bus_read_dev_vendor_id (bus, devfn, &l,60 *1000 ))return NULL ; - dev =alloc_pci_dev (); + dev =pci_alloc_dev ();if (!dev)return NULL ;drivers/scsi/megaraid.c +1
-1@@ -2025,7 +2025,7 @@ megaraid_abort_and_reset(adapter_t *adapter, Scsi_Cmnd *cmd, int aor)static inline int make_local_pdev (adapter_t *adapter,struct pci_dev **pdev) { - *pdev =alloc_pci_dev (); + *pdev =pci_alloc_dev ();if ( *pdev ==NULL )return -1 ;include/linux/pci.h +1
-2@@ -348,7 +348,7 @@ static inline struct pci_dev *pci_physfn(struct pci_dev *dev)return dev; } -extern struct pci_dev *alloc_pci_dev (void ); +extern struct pci_dev *pci_alloc_dev (void );#define to_pci_dev (n) container_of(n, struct pci_dev, dev)#define for_each_pci_dev (d) while ((d = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, d)) != NULL) --1.7.1
--
To unsubscribe from this list: send the line "unsubscribe linux-pci" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH 1/2 PCI: Introduce pci_alloc_dev(struct pci_bus*) to replace alloc_pci_dev()
In reply to Bjorn HelgaasQuoted 1 line
From
906167d9a09babbe189f62944ecb8c0b198a0f64Mon Sep 17 00:00:00 2001
From: Gu Zheng <[email protected]>
Date: Fri, 19 Apr 2013 18:12:32 +0900
Subject: [PATCH 1/2] PCI: Introduce pci_alloc_dev(struct pci_bus*) to replace alloc_pci_dev()
Now here we introduce a new struct pci_dev *pci_alloc_dev(struct pci_bus *bus) to replace alloc_pci_dev(). It take a "struct pci_bus *" argument, so we can alloc a pci device on a target pci bus, and it acquire the reference of the pci_bus.
Since the old alloc_pci_dev() is exported, so we still keep it for a while but mark it as __deprecated.
--- drivers/pci/probe.c | 21 ++++++++++++++++++++- include/linux/pci.h | 4 +++- 2 files changed, 23 insertions(+), 2 deletions(-)
drivers/pci/probe.c +20 -1
@@ -1199,7 +1199,7 @@ static void pci_release_bus_bridge_dev(struct device *dev)kfree (bridge); } -struct pci_dev *alloc_pci_dev (void ) +struct pci_dev *pci_alloc_dev (struct pci_bus *bus) {struct pci_dev *dev;
@@ -1209,6 +1209,25 @@ struct pci_dev *alloc_pci_dev(void)INIT_LIST_HEAD (&dev->bus_list); +if (bus) { +get_device (&bus->dev); + dev->bus = bus; + } + +return dev; +} +EXPORT_SYMBOL (pci_alloc_dev); + +__deprecated struct pci_dev *alloc_pci_dev (void ) +{ +struct pci_dev *dev; +printk (KERN_DEBUG "alloc_pci_dev is deprecated, please use pci_alloc_dev(struct pci_bus *) instead!\n" ); + dev =kzalloc (sizeof (struct pci_dev ),GFP_KERNEL ); +if (!dev) +return NULL ; + +INIT_LIST_HEAD (&dev->bus_list); +return dev; }EXPORT_SYMBOL (alloc_pci_dev);
include/linux/pci.h +3 -1
@@ -348,7 +348,9 @@ static inline struct pci_dev *pci_physfn(struct pci_dev *dev)return dev; } -extern struct pci_dev *alloc_pci_dev (void ); +extern struct pci_dev *pci_alloc_dev (struct pci_bus *bus); + +extern __deprecated struct pci_dev *alloc_pci_dev (void );#define to_pci_dev (n) container_of(n, struct pci_dev, dev)#define for_each_pci_dev (d) while ((d = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, d)) != NULL)
Signature · 1 line
1.7.1
PATCH 2/2 PCI: Convert alloc_pci_dev(void) to pci_alloc_dev(bus) instead
In reply to Bjorn HelgaasQuoted 1 line
From
2535fb1a2502b3d9bebc31f7c7205f42392ea5f9Mon Sep 17 00:00:00 2001
From: Gu Zheng <[email protected]>
Date: Fri, 19 Apr 2013 17:46:36 +0900
Subject: [PATCH 2/2] PCI: Convert alloc_pci_dev(void) to pci_alloc_dev(bus) instead
Use the new pci_alloc_dev(bus) to replace the existing using of alloc_pci_dev(void).
--- arch/powerpc/kernel/pci_of_scan.c | 3 +-- drivers/char/agp/alpha-agp.c | 2 +- drivers/char/agp/parisc-agp.c | 2 +- drivers/pci/iov.c | 2 +- drivers/pci/probe.c | 3 +-- drivers/scsi/megaraid.c | 2 +- 6 files changed, 6 insertions(+), 8 deletions(-)
arch/powerpc/kernel/pci_of_scan.c +1 -2
@@ -128,7 +128,7 @@ struct pci_dev *of_create_pci_dev(struct device_node *node,const char *type;struct pci_slot *slot; - dev =alloc_pci_dev (); + dev =pci_alloc_dev (bus);if (!dev)return NULL ; type =of_get_property (node,"device_type" ,NULL );
@@ -137,7 +137,6 @@ struct pci_dev *of_create_pci_dev(struct device_node *node,pr_debug (" create device, devfn: %x, type: %s\n" , devfn, type); - dev->bus = bus; dev->dev.of_node =of_node_get (node); dev->dev.parent = bus->bridge; dev->dev.bus = &pci_bus_type;
drivers/char/agp/alpha-agp.c +1 -1
@@ -174,7 +174,7 @@ alpha_core_agp_setup(void)/* * Build a fake pci_dev struct */ - pdev =alloc_pci_dev (); + pdev =pci_alloc_dev (NULL );if (!pdev)return -ENOMEM ; pdev->vendor =0xffff ;
drivers/char/agp/parisc-agp.c +1 -1
@@ -333,7 +333,7 @@ parisc_agp_setup(void __iomem *ioc_hpa, void __iomem *lba_hpa)struct agp_bridge_data *bridge;int error =0 ; - fake_bridge_dev =alloc_pci_dev (); + fake_bridge_dev =pci_alloc_dev (NULL );if (!fake_bridge_dev) { error = -ENOMEM ; goto fail;
drivers/pci/iov.c +1 -1
@@ -76,7 +76,7 @@ static int virtfn_add(struct pci_dev *dev, int id, int reset)struct resource *res;struct pci_sriov *iov = dev->sriov; - virtfn =alloc_pci_dev (); + virtfn =pci_alloc_dev (NULL );if (!virtfn)return -ENOMEM ;
drivers/pci/probe.c +1 -2
@@ -1280,11 +1280,10 @@ static struct pci_dev *pci_scan_device(struct pci_bus *bus, int devfn)if (!pci_bus_read_dev_vendor_id (bus, devfn, &l,60 *1000 ))return NULL ; - dev =alloc_pci_dev (); + dev =pci_alloc_dev (bus);if (!dev)return NULL ; - dev->bus = bus; dev->devfn = devfn; dev->vendor = l &0xffff ; dev->device = (l >>16 ) &0xffff ;
drivers/scsi/megaraid.c +1 -1
@@ -2025,7 +2025,7 @@ megaraid_abort_and_reset(adapter_t *adapter, Scsi_Cmnd *cmd, int aor)static inline int make_local_pdev (adapter_t *adapter,struct pci_dev **pdev) { - *pdev =alloc_pci_dev (); + *pdev =pci_alloc_dev (NULL );if ( *pdev ==NULL )return -1 ;
Signature · 1 line
1.7.1
Bjorn Helgaas
maintainerRe: [PATCH 1/2] PCI: Introduce pci_alloc_dev(struct pci_bus*) to replace alloc_pci_dev()
In reply to Gu ZhengQuoted 33 lines · Gu Zheng
From
906167d9a09babbe189f62944ecb8c0b198a0f64Mon Sep 17 00:00:00 2001
From: Gu Zheng <[email protected]>
Date: Fri, 19 Apr 2013 18:12:32 +0900
Subject: [PATCH 1/2] PCI: Introducepci_alloc_dev(struct pci_bus*)to replacealloc_pci_dev()Now here we introduce a new struct
pci_dev*pci_alloc_dev(structpci_bus*bus) to replacealloc_pci_dev(). It take a "structpci_bus*" argument, so we can alloc a pci device on a target pci bus, and it acquire the reference of thepci_bus.
Since the oldalloc_pci_dev()is exported, so we still keep it for a while but mark it as__deprecated.Signed-off-by Gu Zheng <[email protected]>--- drivers/pci/probe.c | 21 ++++++++++++++++++++- include/linux/pci.h | 4 +++- 2 files changed, 23 insertions(+), 2 deletions(-)drivers/pci/probe.c +1
-1@@ -1199,7 +1199,7 @@ static void pci_release_bus_bridge_dev(struct device *dev)kfree (bridge); } -struct pci_dev *alloc_pci_dev (void ) +struct pci_dev *pci_alloc_dev (struct pci_bus *bus) {struct pci_dev *dev;@@ -1209,6 +1209,25 @@ struct pci_dev *alloc_pci_dev(void)INIT_LIST_HEAD (&dev->bus_list);
drivers/pci/probe.c struct pci_dev *alloc_pci_dev(void) · line 1221
Quoted 10 lines
drivers/pci/probe.c +10
-0+if (bus) { +get_device (&bus->dev); + dev->bus = bus; + } + +return dev; +} +EXPORT_SYMBOL (pci_alloc_dev); + +__deprecated struct pci_dev *alloc_pci_dev (void )
I don't think there's any point in marking the function *definition* as deprecated; it only makes sense for the declaration in the header file, so callers of the function will generate warnings.
drivers/pci/probe.c struct pci_dev *alloc_pci_dev(void) · line 1224
Quoted 3 lines
drivers/pci/probe.c +3
-0+{ +struct pci_dev *dev; +printk (KERN_DEBUG "alloc_pci_dev is deprecated, please use pci_alloc_dev(struct pci_bus *) instead!\n" );
I don't want to print a message at run-time, because users will see the message and complain about it, but they can't do anything about it. And neither can we, because it will only be out-of-tree modules that call alloc_pci_dev(). The build-time warning is all we can do.
drivers/pci/probe.c struct pci_dev *alloc_pci_dev(void) · line 1229
Quoted 5 lines
drivers/pci/probe.c +5
-0+ dev =kzalloc (sizeof (struct pci_dev ),GFP_KERNEL ); +if (!dev) +return NULL ; + +INIT_LIST_HEAD (&dev->bus_list);
Can't you implement this as simply:
return pci_alloc_dev(NULL);
Quoted 22 lines
drivers/pci/probe.c +1
-0+return dev; }EXPORT_SYMBOL (alloc_pci_dev);include/linux/pci.h +3
-2@@ -348,7 +348,9 @@ static inline struct pci_dev *pci_physfn(struct pci_dev *dev)return dev; } -extern struct pci_dev *alloc_pci_dev (void ); +extern struct pci_dev *pci_alloc_dev (struct pci_bus *bus); + +extern __deprecated struct pci_dev *alloc_pci_dev (void );#define to_pci_dev (n) container_of(n, struct pci_dev, dev)#define for_each_pci_dev (d) while ((d = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, d)) != NULL) --1.7.1
Bjorn Helgaas
maintainerRe: [PATCH 2/2] PCI: Convert alloc_pci_dev(void) to pci_alloc_dev(bus) instead
In reply to Gu ZhengQuoted 6 lines · Gu Zheng
From
2535fb1a2502b3d9bebc31f7c7205f42392ea5f9Mon Sep 17 00:00:00 2001
From: Gu Zheng <[email protected]>
Date: Fri, 19 Apr 2013 17:46:36 +0900
Subject: [PATCH 2/2] PCI: Convertalloc_pci_dev(void)topci_alloc_dev(bus)insteadUse the new
pci_alloc_dev(bus)to replace the existing using ofalloc_pci_dev(void).
You didn't do anything with Yinghai's comment. He's 100% correct: you have to add the put_device() that corresponds to the new get_device() calls you're adding. Both have to be in the same patch.
Quoted 107 lines
Signed-off-by Gu Zheng <[email protected]>--- arch/powerpc/kernel/pci_of_scan.c | 3 +-- drivers/char/agp/alpha-agp.c | 2 +- drivers/char/agp/parisc-agp.c | 2 +- drivers/pci/iov.c | 2 +- drivers/pci/probe.c | 3 +-- drivers/scsi/megaraid.c | 2 +- 6 files changed, 6 insertions(+), 8 deletions(-)arch/powerpc/kernel/pci_of_scan.c +1
-2@@ -128,7 +128,7 @@ struct pci_dev *of_create_pci_dev(struct device_node *node,const char *type;struct pci_slot *slot; - dev =alloc_pci_dev (); + dev =pci_alloc_dev (bus);if (!dev)return NULL ; type =of_get_property (node,"device_type" ,NULL );@@ -137,7 +137,6 @@ struct pci_dev *of_create_pci_dev(struct device_node *node,pr_debug (" create device, devfn: %x, type: %s\n" , devfn, type); - dev->bus = bus; dev->dev.of_node =of_node_get (node); dev->dev.parent = bus->bridge; dev->dev.bus = &pci_bus_type;drivers/char/agp/alpha-agp.c +1
-1@@ -174,7 +174,7 @@ alpha_core_agp_setup(void)/* * Build a fake pci_dev struct */ - pdev =alloc_pci_dev (); + pdev =pci_alloc_dev (NULL );if (!pdev)return -ENOMEM ; pdev->vendor =0xffff ;drivers/char/agp/parisc-agp.c +1
-1@@ -333,7 +333,7 @@ parisc_agp_setup(void __iomem *ioc_hpa, void __iomem *lba_hpa)struct agp_bridge_data *bridge;int error =0 ; - fake_bridge_dev =alloc_pci_dev (); + fake_bridge_dev =pci_alloc_dev (NULL );if (!fake_bridge_dev) { error = -ENOMEM ; goto fail;drivers/pci/iov.c +1
-1@@ -76,7 +76,7 @@ static int virtfn_add(struct pci_dev *dev, int id, int reset)struct resource *res;struct pci_sriov *iov = dev->sriov; - virtfn =alloc_pci_dev (); + virtfn =pci_alloc_dev (NULL );if (!virtfn)return -ENOMEM ;drivers/pci/probe.c +1
-2@@ -1280,11 +1280,10 @@ static struct pci_dev *pci_scan_device(struct pci_bus *bus, int devfn)if (!pci_bus_read_dev_vendor_id (bus, devfn, &l,60 *1000 ))return NULL ; - dev =alloc_pci_dev (); + dev =pci_alloc_dev (bus);if (!dev)return NULL ; - dev->bus = bus; dev->devfn = devfn; dev->vendor = l &0xffff ; dev->device = (l >>16 ) &0xffff ;drivers/scsi/megaraid.c +1
-2@@ -2025,7 +2025,7 @@ megaraid_abort_and_reset(adapter_t *adapter, Scsi_Cmnd *cmd, int aor)static inline int make_local_pdev (adapter_t *adapter,struct pci_dev **pdev) { - *pdev =alloc_pci_dev (); + *pdev =pci_alloc_dev (NULL );if ( *pdev ==NULL )return -1 ; --1.7.1
--
To unsubscribe from this list: send the line "unsubscribe linux-pci" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 1/2] PCI: Introduce pci_alloc_dev(struct pci_bus*) to replace alloc_pci_dev()
In reply to Bjorn HelgaasQuoted 49 lines · Bjorn Helgaas
Quoted 33 lines · Gu Zheng
From
906167d9a09babbe189f62944ecb8c0b198a0f64Mon Sep 17 00:00:00 2001
From: Gu Zheng <[email protected]>
Date: Fri, 19 Apr 2013 18:12:32 +0900
Subject: [PATCH 1/2] PCI: Introducepci_alloc_dev(struct pci_bus*)to replacealloc_pci_dev()Now here we introduce a new struct
pci_dev*pci_alloc_dev(structpci_bus*bus) to replacealloc_pci_dev(). It take a "structpci_bus*" argument, so we can alloc a pci device on a target pci bus, and it acquire the reference of thepci_bus.
Since the oldalloc_pci_dev()is exported, so we still keep it for a while but mark it as__deprecated.Signed-off-by Gu Zheng <[email protected]>--- drivers/pci/probe.c | 21 ++++++++++++++++++++- include/linux/pci.h | 4 +++- 2 files changed, 23 insertions(+), 2 deletions(-)drivers/pci/probe.c +1
-1@@ -1199,7 +1199,7 @@ static void pci_release_bus_bridge_dev(struct device *dev)kfree (bridge); } -struct pci_dev *alloc_pci_dev (void ) +struct pci_dev *pci_alloc_dev (struct pci_bus *bus) {struct pci_dev *dev;@@ -1209,6 +1209,25 @@ struct pci_dev *alloc_pci_dev(void)INIT_LIST_HEAD (&dev->bus_list);drivers/pci/probe.c struct pci_dev *alloc_pci_dev(void) · line 1221
Quoted 10 lines
drivers/pci/probe.c +10
-0+if (bus) { +get_device (&bus->dev); + dev->bus = bus; + } + +return dev; +} +EXPORT_SYMBOL (pci_alloc_dev); + +__deprecated struct pci_dev *alloc_pci_dev (void )I don't think there's any point in marking the function *definition* as deprecated; it only makes sense for the declaration in the header file, so callers of the function will generate warnings.
Quoted 8 lines
drivers/pci/probe.c struct pci_dev *alloc_pci_dev(void) · line 1224
Quoted 3 lines
drivers/pci/probe.c +3
-0+{ +struct pci_dev *dev; +printk (KERN_DEBUG "alloc_pci_dev is deprecated, please use pci_alloc_dev(struct pci_bus *) instead!\n" );I don't want to print a message at run-time, because users will see the message and complain about it, but they can't do anything about it. And neither can we, because it will only be out-of-tree modules that call
alloc_pci_dev(). The build-time warning is all we can do.
Yes, totally agree .
Quoted 10 lines
drivers/pci/probe.c struct pci_dev *alloc_pci_dev(void) · line 1229
Quoted 6 lines
drivers/pci/probe.c +5
-0+ dev =kzalloc (sizeof (struct pci_dev ),GFP_KERNEL ); +if (!dev) +return NULL ; + +INIT_LIST_HEAD (&dev->bus_list);Can't you implement this as simply:
return pci_alloc_dev(NULL);
Yes, I think it's better to keep the old API, and modify it to call the new one, this makes the modules which call the old fashion API feel smoothly. and the new modules can use the new API.
Quoted 28 lines
Quoted 21 lines
drivers/pci/probe.c +1
-0+return dev; }EXPORT_SYMBOL (alloc_pci_dev);include/linux/pci.h +3
-2@@ -348,7 +348,9 @@ static inline struct pci_dev *pci_physfn(struct pci_dev *dev)return dev; } -extern struct pci_dev *alloc_pci_dev (void ); +extern struct pci_dev *pci_alloc_dev (struct pci_bus *bus); + +extern __deprecated struct pci_dev *alloc_pci_dev (void );#define to_pci_dev (n) container_of(n, struct pci_dev, dev)#define for_each_pci_dev (d) while ((d = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, d)) != NULL) --Quoted 2 lines
1.7.1
--
To unsubscribe from this list: send the line "unsubscribe linux-pci" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 1/2] PCI: Introduce pci_alloc_dev(struct pci_bus*) to replace alloc_pci_dev()
In reply to Bjorn HelgaasHi Bjorn,
Sorry for the later reply!
Quoted 34 lines · Bjorn Helgaas
Quoted 33 lines · Gu Zheng
From
906167d9a09babbe189f62944ecb8c0b198a0f64Mon Sep 17 00:00:00 2001
From: Gu Zheng <[email protected]>
Date: Fri, 19 Apr 2013 18:12:32 +0900
Subject: [PATCH 1/2] PCI: Introducepci_alloc_dev(struct pci_bus*)to replacealloc_pci_dev()Now here we introduce a new struct
pci_dev*pci_alloc_dev(structpci_bus*bus) to replacealloc_pci_dev(). It take a "structpci_bus*" argument, so we can alloc a pci device on a target pci bus, and it acquire the reference of thepci_bus.
Since the oldalloc_pci_dev()is exported, so we still keep it for a while but mark it as__deprecated.Signed-off-by Gu Zheng <[email protected]>--- drivers/pci/probe.c | 21 ++++++++++++++++++++- include/linux/pci.h | 4 +++- 2 files changed, 23 insertions(+), 2 deletions(-)drivers/pci/probe.c +1
-1@@ -1199,7 +1199,7 @@ static void pci_release_bus_bridge_dev(struct device *dev)kfree (bridge); } -struct pci_dev *alloc_pci_dev (void ) +struct pci_dev *pci_alloc_dev (struct pci_bus *bus) {struct pci_dev *dev;@@ -1209,6 +1209,25 @@ struct pci_dev *alloc_pci_dev(void)INIT_LIST_HEAD (&dev->bus_list);
Quoted 14 lines
drivers/pci/probe.c struct pci_dev *alloc_pci_dev(void) · line 1221
Quoted 10 lines
drivers/pci/probe.c +10
-0+if (bus) { +get_device (&bus->dev); + dev->bus = bus; + } + +return dev; +} +EXPORT_SYMBOL (pci_alloc_dev); + +__deprecated struct pci_dev *alloc_pci_dev (void )I don't think there's any point in marking the function *definition* as deprecated; it only makes sense for the declaration in the header file, so callers of the function will generate warnings.
Thanks for your explaining, I'll fix it in the right way.
Quoted 9 lines
drivers/pci/probe.c struct pci_dev *alloc_pci_dev(void) · line 1224
Quoted 4 lines
drivers/pci/probe.c +3
-0+{ +struct pci_dev *dev; +printk (KERN_DEBUG "alloc_pci_dev is deprecated, please use pci_alloc_dev(struct pci_bus *) instead!\n" );I don't want to print a message at run-time, because users will see the message and complain about it, but they can't do anything about it. And neither can we, because it will only be out-of-tree modules that call
alloc_pci_dev(). The build-time warning is all we can do.
Yeah, it seems useless here. I'll remove it.
Quoted 10 lines
drivers/pci/probe.c struct pci_dev *alloc_pci_dev(void) · line 1229
Quoted 6 lines
drivers/pci/probe.c +5
-0+ dev =kzalloc (sizeof (struct pci_dev ),GFP_KERNEL ); +if (!dev) +return NULL ; + +INIT_LIST_HEAD (&dev->bus_list);Can't you implement this as simply:
return pci_alloc_dev(NULL);
Agree, it can simplify the code, and make the later removal of the old alloc_pci_dev() smoothly.
Quoted 24 lines
Quoted 23 lines
drivers/pci/probe.c +1
-0+return dev; }EXPORT_SYMBOL (alloc_pci_dev);include/linux/pci.h +3
-2@@ -348,7 +348,9 @@ static inline struct pci_dev *pci_physfn(struct pci_dev *dev)return dev; } -extern struct pci_dev *alloc_pci_dev (void ); +extern struct pci_dev *pci_alloc_dev (struct pci_bus *bus); + +extern __deprecated struct pci_dev *alloc_pci_dev (void );#define to_pci_dev (n) container_of(n, struct pci_dev, dev)#define for_each_pci_dev (d) while ((d = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, d)) != NULL) --1.7.1
Re: [PATCH 1/2] PCI: Introduce pci_alloc_dev(struct pci_bus*) to replace alloc_pci_dev()
In reply to Mike QiuQuoted 66 lines · Mike Qiu
Quoted 49 lines · Bjorn Helgaas
Quoted 33 lines · Gu Zheng
From
906167d9a09babbe189f62944ecb8c0b198a0f64Mon Sep 17 00:00:00 2001
From: Gu Zheng <[email protected]>
Date: Fri, 19 Apr 2013 18:12:32 +0900
Subject: [PATCH 1/2] PCI: Introducepci_alloc_dev(struct pci_bus*)to replacealloc_pci_dev()Now here we introduce a new struct
pci_dev*pci_alloc_dev(structpci_bus*bus) to replacealloc_pci_dev(). It take a "structpci_bus*" argument, so we can alloc a pci device on a target pci bus, and it acquire the reference of thepci_bus.
Since the oldalloc_pci_dev()is exported, so we still keep it for a while but mark it as__deprecated.Signed-off-by Gu Zheng <[email protected]>--- drivers/pci/probe.c | 21 ++++++++++++++++++++- include/linux/pci.h | 4 +++- 2 files changed, 23 insertions(+), 2 deletions(-)drivers/pci/probe.c +1
-1@@ -1199,7 +1199,7 @@ static void pci_release_bus_bridge_dev(struct device *dev)kfree (bridge); } -struct pci_dev *alloc_pci_dev (void ) +struct pci_dev *pci_alloc_dev (struct pci_bus *bus) {struct pci_dev *dev;@@ -1209,6 +1209,25 @@ struct pci_dev *alloc_pci_dev(void)INIT_LIST_HEAD (&dev->bus_list);drivers/pci/probe.c struct pci_dev *alloc_pci_dev(void) · line 1221
Quoted 10 lines
drivers/pci/probe.c +10
-0+if (bus) { +get_device (&bus->dev); + dev->bus = bus; + } + +return dev; +} +EXPORT_SYMBOL (pci_alloc_dev); + +__deprecated struct pci_dev *alloc_pci_dev (void )I don't think there's any point in marking the function *definition* as deprecated; it only makes sense for the declaration in the header file, so callers of the function will generate warnings.
Quoted 8 lines
drivers/pci/probe.c struct pci_dev *alloc_pci_dev(void) · line 1224
Quoted 3 lines
drivers/pci/probe.c +3
-0+{ +struct pci_dev *dev; +printk (KERN_DEBUG "alloc_pci_dev is deprecated, please use pci_alloc_dev(struct pci_bus *) instead!\n" );I don't want to print a message at run-time, because users will see the message and complain about it, but they can't do anything about it. And neither can we, because it will only be out-of-tree modules that call
alloc_pci_dev(). The build-time warning is all we can do.Yes, totally agree .
Quoted 7 lines
Quoted 6 lines
drivers/pci/probe.c +5
-0+ dev =kzalloc (sizeof (struct pci_dev ),GFP_KERNEL ); +if (!dev) +return NULL ; + +INIT_LIST_HEAD (&dev->bus_list);
Quoted 6 lines
Quoted 3 lines
Can't you implement this as simply:
return pci_alloc_dev(NULL);Yes, I think it's better to keep the old API, and modify it to call the new one, this makes the modules which call the old fashion API feel smoothly. and the new modules can use the new API.
Hi Mike,
You are right! Thanks for your suggestion!
Regards,
Gu
Quoted 31 lines
Quoted 28 lines
Quoted 21 lines
drivers/pci/probe.c +1
-0+return dev; }EXPORT_SYMBOL (alloc_pci_dev);include/linux/pci.h +3
-2@@ -348,7 +348,9 @@ static inline struct pci_dev *pci_physfn(struct pci_dev *dev)return dev; } -extern struct pci_dev *alloc_pci_dev (void ); +extern struct pci_dev *pci_alloc_dev (struct pci_bus *bus); + +extern __deprecated struct pci_dev *alloc_pci_dev (void );#define to_pci_dev (n) container_of(n, struct pci_dev, dev)#define for_each_pci_dev (d) while ((d = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, d)) != NULL) --Quoted 2 lines
1.7.1
--
To unsubscribe from this list: send the line "unsubscribe linux-pci" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 2/2] PCI: Convert alloc_pci_dev(void) to pci_alloc_dev(bus) instead
In reply to Bjorn HelgaasQuoted 11 lines · Bjorn Helgaas
Quoted 6 lines · Gu Zheng
From
2535fb1a2502b3d9bebc31f7c7205f42392ea5f9Mon Sep 17 00:00:00 2001
From: Gu Zheng <[email protected]>
Date: Fri, 19 Apr 2013 17:46:36 +0900
Subject: [PATCH 2/2] PCI: Convertalloc_pci_dev(void)topci_alloc_dev(bus)insteadUse the new
pci_alloc_dev(bus)to replace the existing using ofalloc_pci_dev(void).You didn't do anything with Yinghai's comment. He's 100% correct: you have to add the
put_device()that corresponds to the newget_device()calls you're adding. Both have to be in the same patch.
Hi Bjorn,
Thanks for your reminder, Yinghai's comment is completely right, the get_device()/put_device() should come in pairs.
I'll add the put_device() in the next version.
Best regards,
Gu
Quoted 109 lines
Quoted 108 lines
Signed-off-by Gu Zheng <[email protected]>--- arch/powerpc/kernel/pci_of_scan.c | 3 +-- drivers/char/agp/alpha-agp.c | 2 +- drivers/char/agp/parisc-agp.c | 2 +- drivers/pci/iov.c | 2 +- drivers/pci/probe.c | 3 +-- drivers/scsi/megaraid.c | 2 +- 6 files changed, 6 insertions(+), 8 deletions(-)arch/powerpc/kernel/pci_of_scan.c +1
-2@@ -128,7 +128,7 @@ struct pci_dev *of_create_pci_dev(struct device_node *node,const char *type;struct pci_slot *slot; - dev =alloc_pci_dev (); + dev =pci_alloc_dev (bus);if (!dev)return NULL ; type =of_get_property (node,"device_type" ,NULL );@@ -137,7 +137,6 @@ struct pci_dev *of_create_pci_dev(struct device_node *node,pr_debug (" create device, devfn: %x, type: %s\n" , devfn, type); - dev->bus = bus; dev->dev.of_node =of_node_get (node); dev->dev.parent = bus->bridge; dev->dev.bus = &pci_bus_type;drivers/char/agp/alpha-agp.c +1
-1@@ -174,7 +174,7 @@ alpha_core_agp_setup(void)/* * Build a fake pci_dev struct */ - pdev =alloc_pci_dev (); + pdev =pci_alloc_dev (NULL );if (!pdev)return -ENOMEM ; pdev->vendor =0xffff ;drivers/char/agp/parisc-agp.c +1
-1@@ -333,7 +333,7 @@ parisc_agp_setup(void __iomem *ioc_hpa, void __iomem *lba_hpa)struct agp_bridge_data *bridge;int error =0 ; - fake_bridge_dev =alloc_pci_dev (); + fake_bridge_dev =pci_alloc_dev (NULL );if (!fake_bridge_dev) { error = -ENOMEM ; goto fail;drivers/pci/iov.c +1
-1@@ -76,7 +76,7 @@ static int virtfn_add(struct pci_dev *dev, int id, int reset)struct resource *res;struct pci_sriov *iov = dev->sriov; - virtfn =alloc_pci_dev (); + virtfn =pci_alloc_dev (NULL );if (!virtfn)return -ENOMEM ;drivers/pci/probe.c +1
-2@@ -1280,11 +1280,10 @@ static struct pci_dev *pci_scan_device(struct pci_bus *bus, int devfn)if (!pci_bus_read_dev_vendor_id (bus, devfn, &l,60 *1000 ))return NULL ; - dev =alloc_pci_dev (); + dev =pci_alloc_dev (bus);if (!dev)return NULL ; - dev->bus = bus; dev->devfn = devfn; dev->vendor = l &0xffff ; dev->device = (l >>16 ) &0xffff ;drivers/scsi/megaraid.c +1
-2@@ -2025,7 +2025,7 @@ megaraid_abort_and_reset(adapter_t *adapter, Scsi_Cmnd *cmd, int aor)static inline int make_local_pdev (adapter_t *adapter,struct pci_dev **pdev) { - *pdev =alloc_pci_dev (); + *pdev =pci_alloc_dev (NULL );if ( *pdev ==NULL )return -1 ; --1.7.1
--
To unsubscribe from this list: send the line "unsubscribe linux-pci" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH v2 1/2 PCI: Introduce pci_alloc_dev(struct pci_bus*) to replace alloc_pci_dev()
In reply to Bjorn HelgaasQuoted 1 line
From
d66f5b255abeedfbeff212b1e4bc3d8f4ae908e3Mon Sep 17 00:00:00 2001
From: Gu Zheng <[email protected]>
Date: Mon, 22 Apr 2013 19:04:07 +0900
Subject: [PATCH v2 1/2] PCI: Introduce pci_alloc_dev(struct pci_bus*) to replace alloc_pci_dev()
Now here we introduce a new struct pci_dev *pci_alloc_dev(struct pci_bus *bus) to replace alloc_pci_dev(). It take a "struct pci_bus *" argument, so we can alloc a pci device on a target pci bus, and it acquire the reference of the pci_bus.
Since the old alloc_pci_dev() is exported, so we still keep it for a while but mark it as __deprecated.
v2:
Updated per code reviews from Bjorn Helgaas and Mike Qiu.
--- drivers/pci/probe.c | 13 ++++++++++++- include/linux/pci.h | 4 +++- 2 files changed, 15 insertions(+), 2 deletions(-)
drivers/pci/probe.c +12 -1
@@ -1199,7 +1199,7 @@ static void pci_release_bus_bridge_dev(struct device *dev)kfree (bridge); } -struct pci_dev *alloc_pci_dev (void ) +struct pci_dev *pci_alloc_dev (struct pci_bus *bus) {struct pci_dev *dev;
@@ -1209,8 +1209,19 @@ struct pci_dev *alloc_pci_dev(void)INIT_LIST_HEAD (&dev->bus_list); +if (bus) { +get_device (&bus->dev); + dev->bus = bus; + } +return dev; } +EXPORT_SYMBOL (pci_alloc_dev); + +struct pci_dev *alloc_pci_dev (void ) +{ +return pci_alloc_dev (NULL ); +}EXPORT_SYMBOL (alloc_pci_dev); bool pci_bus_read_dev_vendor_id(struct pci_bus *bus, int devfn, u32 *l,
include/linux/pci.h +3 -1
@@ -348,7 +348,9 @@ static inline struct pci_dev *pci_physfn(struct pci_dev *dev)return dev; } -extern struct pci_dev *alloc_pci_dev (void ); +extern struct pci_dev *pci_alloc_dev (struct pci_bus *bus); + +extern __deprecated struct pci_dev *alloc_pci_dev (void );#define to_pci_dev (n) container_of(n, struct pci_dev, dev)#define for_each_pci_dev (d) while ((d = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, d)) != NULL)
Signature · 1 line
1.7.7
PATCH v2 2/2 PCI: Convert alloc_pci_dev(void) to pci_alloc_dev(bus) instead
In reply to Bjorn HelgaasQuoted 1 line
From
b01e61759f894b651ed3bb39c9fc18e0b66d7cb3Mon Sep 17 00:00:00 2001
From: GuZheng <[email protected]>
Date: Tue, 23 Apr 2013 14:01:39 +0800
Subject: [PATCH v2 2/2] PCI: Convert alloc_pci_dev(void) to pci_alloc_dev(bus)
instead
Use the new pci_alloc_dev(bus) to replace the existing using of alloc_pci_dev(void). And new functions pci_bus_get/put() are introdued to hide pci_bus' reference management.
v2:
Follow Yinghai's suggestions to reduce pci_bus' ref when destroying pci device. Add new functions pci_bus_get/put() to hide pci_bus' reference management.
--- arch/powerpc/kernel/pci_of_scan.c | 3 +-- arch/sparc/kernel/pci.c | 3 +-- drivers/char/agp/alpha-agp.c | 2 +- drivers/char/agp/parisc-agp.c | 2 +- drivers/pci/bus.c | 15 +++++++++++++++ drivers/pci/iov.c | 8 +++++--- drivers/pci/probe.c | 9 +++------ drivers/pci/remove.c | 2 ++ drivers/scsi/megaraid.c | 2 +- include/linux/pci.h | 3 +++ 10 files changed, 33 insertions(+), 16 deletions(-)
arch/powerpc/kernel/pci_of_scan.c +1 -2
@@ -128,7 +128,7 @@ struct pci_dev *of_create_pci_dev(struct device_node *node,const char *type;struct pci_slot *slot; - dev =alloc_pci_dev (); + dev =pci_alloc_dev (bus);if (!dev)return NULL ; type =of_get_property (node,"device_type" ,NULL );
@@ -137,7 +137,6 @@ struct pci_dev *of_create_pci_dev(struct device_node *node,pr_debug (" create device, devfn: %x, type: %s\n" , devfn, type); - dev->bus = bus; dev->dev.of_node =of_node_get (node); dev->dev.parent = bus->bridge; dev->dev.bus = &pci_bus_type;
arch/sparc/kernel/pci.c +1 -2
@@ -254,7 +254,7 @@ static struct pci_dev *of_create_pci_dev(struct pci_pbm_info *pbm,const char *type;u32 class; - dev =alloc_pci_dev (); + dev =pci_alloc_dev (bus);if (!dev)return NULL ;
@@ -281,7 +281,6 @@ static struct pci_dev *of_create_pci_dev(struct pci_pbm_info *pbm,printk (" create device, devfn: %x, type: %s\n" , devfn, type); - dev->bus = bus; dev->sysdata = node; dev->dev.parent = bus->bridge; dev->dev.bus = &pci_bus_type;
drivers/char/agp/alpha-agp.c +1 -1
@@ -174,7 +174,7 @@ alpha_core_agp_setup(void)/* * Build a fake pci_dev struct */ - pdev =alloc_pci_dev (); + pdev =pci_alloc_dev (NULL );if (!pdev)return -ENOMEM ; pdev->vendor =0xffff ;
drivers/char/agp/parisc-agp.c +1 -1
@@ -333,7 +333,7 @@ parisc_agp_setup(void __iomem *ioc_hpa, void __iomem *lba_hpa)struct agp_bridge_data *bridge;int error =0 ; - fake_bridge_dev =alloc_pci_dev (); + fake_bridge_dev =pci_alloc_dev (NULL );if (!fake_bridge_dev) { error = -ENOMEM ; goto fail;
drivers/pci/bus.c +15 -0
@@ -18,6 +18,21 @@#include "pci.h" +struct pci_bus *pci_bus_get (struct pci_bus *bus) +{ +if (bus) +get_device (&bus->dev); +return bus; +} +EXPORT_SYMBOL (pci_bus_get); + +void pci_bus_put (struct pci_bus *bus) +{ +if (bus) +put_device (&bus->dev); +} +EXPORT_SYMBOL (pci_bus_put); +void pci_add_resource_offset (struct list_head *resources,struct resource *res,resource_size_t offset) {
drivers/pci/iov.c +5 -3
@@ -75,18 +75,20 @@ static int virtfn_add(struct pci_dev *dev, int id, int reset)struct pci_dev *virtfn;struct resource *res;struct pci_sriov *iov = dev->sriov; +struct pci_bus *bus; - virtfn =alloc_pci_dev (); + virtfn =pci_alloc_dev (NULL );if (!virtfn)return -ENOMEM ;mutex_lock (&iov->dev->sriov->lock); - virtfn->bus =virtfn_add_bus (dev->bus,virtfn_bus (dev, id)); -if (!virtfn->bus) { + bus =virtfn_add_bus (dev->bus,virtfn_bus (dev, id)); +if (!bus) {kfree (virtfn);mutex_unlock (&iov->dev->sriov->lock);return -ENOMEM ; } + virtfn->bus =pci_bus_get (bus); virtfn->devfn =virtfn_devfn (dev, id); virtfn->vendor = dev->vendor;pci_read_config_word (dev, iov->pos +PCI_SRIOV_VF_DID , &virtfn->device);
drivers/pci/probe.c +3 -6
@@ -1209,10 +1209,8 @@ struct pci_dev *pci_alloc_dev(struct pci_bus *bus)INIT_LIST_HEAD (&dev->bus_list); -if (bus) { -get_device (&bus->dev); - dev->bus = bus; - } +if (bus) + dev->bus =pci_bus_get (bus);return dev; }
@@ -1272,11 +1270,10 @@ static struct pci_dev *pci_scan_device(struct pci_bus *bus, int devfn)if (!pci_bus_read_dev_vendor_id (bus, devfn, &l,60 *1000 ))return NULL ; - dev =alloc_pci_dev (); + dev =pci_alloc_dev (bus);if (!dev)return NULL ; - dev->bus = bus; dev->devfn = devfn; dev->vendor = l &0xffff ; dev->device = (l >>16 ) &0xffff ;
drivers/pci/remove.c +2 -0
@@ -38,6 +38,8 @@ static void pci_destroy_dev(struct pci_dev *dev)list_del (&dev->bus_list);up_write (&pci_bus_sem); +pci_bus_put (dev->bus); +pci_free_resources (dev);put_device (&dev->dev); }
drivers/scsi/megaraid.c +1 -1
@@ -2025,7 +2025,7 @@ megaraid_abort_and_reset(adapter_t *adapter, Scsi_Cmnd *cmd, int aor)static inline int make_local_pdev (adapter_t *adapter,struct pci_dev **pdev) { - *pdev =alloc_pci_dev (); + *pdev =pci_alloc_dev (NULL );if ( *pdev ==NULL )return -1 ;
include/linux/pci.h +3 -0
@@ -1002,6 +1002,9 @@ int pci_request_selected_regions_exclusive(struct pci_dev *, int, const char *);void pci_release_selected_regions (struct pci_dev *,int );/* drivers/pci/bus.c */ +extern struct pci_bus *pci_bus_get (struct pci_bus *bus); +extern void pci_bus_put (struct pci_bus *bus); +void pci_add_resource (struct list_head *resources,struct resource *res);void pci_add_resource_offset (struct list_head *resources,struct resource *res,resource_size_t offset);
Signature · 1 line
1.7.7
Re: [PATCH v2 2/2] PCI: Convert alloc_pci_dev(void) to pci_alloc_dev(bus) instead
Quoted 111 lines · Gu Zheng
From
b01e61759f894b651ed3bb39c9fc18e0b66d7cb3Mon Sep 17 00:00:00 2001
From: GuZheng <[email protected]>
Date: Tue, 23 Apr 2013 14:01:39 +0800
Subject: [PATCH v2 2/2] PCI: Convertalloc_pci_dev(void)topci_alloc_dev(bus)
insteadUse the new
pci_alloc_dev(bus)to replace the existing using ofalloc_pci_dev(void). And new functions pci_bus_get/put() are introdued to hidepci_bus' reference management.v2:
Follow Yinghai's suggestions to reducepci_bus' ref when destroying pci device. Add new functions pci_bus_get/put() to hidepci_bus' reference management.Signed-off-by Gu Zheng <[email protected]>--- arch/powerpc/kernel/pci_of_scan.c | 3 +-- arch/sparc/kernel/pci.c | 3 +-- drivers/char/agp/alpha-agp.c | 2 +- drivers/char/agp/parisc-agp.c | 2 +- drivers/pci/bus.c | 15 +++++++++++++++ drivers/pci/iov.c | 8 +++++--- drivers/pci/probe.c | 9 +++------ drivers/pci/remove.c | 2 ++ drivers/scsi/megaraid.c | 2 +- include/linux/pci.h | 3 +++ 10 files changed, 33 insertions(+), 16 deletions(-)arch/powerpc/kernel/pci_of_scan.c +1
-2@@ -128,7 +128,7 @@ struct pci_dev *of_create_pci_dev(struct device_node *node,const char *type;struct pci_slot *slot; - dev =alloc_pci_dev (); + dev =pci_alloc_dev (bus);if (!dev)return NULL ; type =of_get_property (node,"device_type" ,NULL );@@ -137,7 +137,6 @@ struct pci_dev *of_create_pci_dev(struct device_node *node,pr_debug (" create device, devfn: %x, type: %s\n" , devfn, type); - dev->bus = bus; dev->dev.of_node =of_node_get (node); dev->dev.parent = bus->bridge; dev->dev.bus = &pci_bus_type;arch/sparc/kernel/pci.c +1
-2@@ -254,7 +254,7 @@ static struct pci_dev *of_create_pci_dev(struct pci_pbm_info *pbm,const char *type;u32 class; - dev =alloc_pci_dev (); + dev =pci_alloc_dev (bus);if (!dev)return NULL ;@@ -281,7 +281,6 @@ static struct pci_dev *of_create_pci_dev(struct pci_pbm_info *pbm,printk (" create device, devfn: %x, type: %s\n" , devfn, type); - dev->bus = bus; dev->sysdata = node; dev->dev.parent = bus->bridge; dev->dev.bus = &pci_bus_type;drivers/char/agp/alpha-agp.c +1
-1@@ -174,7 +174,7 @@ alpha_core_agp_setup(void)/* * Build a fake pci_dev struct */ - pdev =alloc_pci_dev (); + pdev =pci_alloc_dev (NULL );if (!pdev)return -ENOMEM ; pdev->vendor =0xffff ;drivers/char/agp/parisc-agp.c +1
-1@@ -333,7 +333,7 @@ parisc_agp_setup(void __iomem *ioc_hpa, void __iomem *lba_hpa)struct agp_bridge_data *bridge;int error =0 ; - fake_bridge_dev =alloc_pci_dev (); + fake_bridge_dev =pci_alloc_dev (NULL );if (!fake_bridge_dev) { error = -ENOMEM ; goto fail;drivers/pci/bus.c +8
-0@@ -18,6 +18,21 @@#include "pci.h" +struct pci_bus *pci_bus_get (struct pci_bus *bus) +{ +if (bus) +get_device (&bus->dev); +return bus; +} +EXPORT_SYMBOL (pci_bus_get); +
drivers/pci/bus.c line 38
Quoted 10 lines
drivers/pci/bus.c +7
-0+void pci_bus_put (struct pci_bus *bus) +{ +if (bus) +put_device (&bus->dev); +} +EXPORT_SYMBOL (pci_bus_put); +void pci_add_resource_offset (struct list_head *resources,struct resource *res,resource_size_t offset) {
Hi Zheng,
Could you please help to split addition of pci_bus_get() and pci_bus_put()
into a separate patch? I'm working on some patches which depends on this.
Quoted 33 lines
drivers/pci/iov.c +5
-3@@ -75,18 +75,20 @@ static int virtfn_add(struct pci_dev *dev, int id, int reset)struct pci_dev *virtfn;struct resource *res;struct pci_sriov *iov = dev->sriov; +struct pci_bus *bus; - virtfn =alloc_pci_dev (); + virtfn =pci_alloc_dev (NULL );if (!virtfn)return -ENOMEM ;mutex_lock (&iov->dev->sriov->lock); - virtfn->bus =virtfn_add_bus (dev->bus,virtfn_bus (dev, id)); -if (!virtfn->bus) { + bus =virtfn_add_bus (dev->bus,virtfn_bus (dev, id)); +if (!bus) {kfree (virtfn);mutex_unlock (&iov->dev->sriov->lock);return -ENOMEM ; } + virtfn->bus =pci_bus_get (bus); virtfn->devfn =virtfn_devfn (dev, id); virtfn->vendor = dev->vendor;pci_read_config_word (dev, iov->pos +PCI_SRIOV_VF_DID , &virtfn->device);drivers/pci/probe.c +0
-0
drivers/pci/probe.c struct pci_dev *pci_alloc_dev(struct pci_bus *bus) · line 1212
Quoted 8 lines
drivers/pci/probe.c +1
-4@@ -1209,10 +1209,8 @@ struct pci_dev *pci_alloc_dev(struct pci_bus *bus)INIT_LIST_HEAD (&dev->bus_list); -if (bus) { -get_device (&bus->dev); - dev->bus = bus; - } +if (bus)
How about remove above redundant check?
Quoted 58 lines
drivers/pci/probe.c +2
-2+ dev->bus =pci_bus_get (bus);return dev; }@@ -1272,11 +1270,10 @@ static struct pci_dev *pci_scan_device(struct pci_bus *bus, int devfn)if (!pci_bus_read_dev_vendor_id (bus, devfn, &l,60 *1000 ))return NULL ; - dev =alloc_pci_dev (); + dev =pci_alloc_dev (bus);if (!dev)return NULL ; - dev->bus = bus; dev->devfn = devfn; dev->vendor = l &0xffff ; dev->device = (l >>16 ) &0xffff ;drivers/pci/remove.c +2
-0@@ -38,6 +38,8 @@ static void pci_destroy_dev(struct pci_dev *dev)list_del (&dev->bus_list);up_write (&pci_bus_sem); +pci_bus_put (dev->bus); +pci_free_resources (dev);put_device (&dev->dev); }drivers/scsi/megaraid.c +1
-1@@ -2025,7 +2025,7 @@ megaraid_abort_and_reset(adapter_t *adapter, Scsi_Cmnd *cmd, int aor)static inline int make_local_pdev (adapter_t *adapter,struct pci_dev **pdev) { - *pdev =alloc_pci_dev (); + *pdev =pci_alloc_dev (NULL );if ( *pdev ==NULL )return -1 ;include/linux/pci.h +3
-0@@ -1002,6 +1002,9 @@ int pci_request_selected_regions_exclusive(struct pci_dev *, int, const char *);void pci_release_selected_regions (struct pci_dev *,int );/* drivers/pci/bus.c */ +extern struct pci_bus *pci_bus_get (struct pci_bus *bus); +extern void pci_bus_put (struct pci_bus *bus); +void pci_add_resource (struct list_head *resources,struct resource *res);void pci_add_resource_offset (struct list_head *resources,struct resource *res,resource_size_t offset);
Re: [PATCH v2 2/2] PCI: Convert alloc_pci_dev(void) to pci_alloc_dev(bus) instead
In reply to Gu ZhengQuoted 6 lines · Gu Zheng
From
b01e61759f894b651ed3bb39c9fc18e0b66d7cb3Mon Sep 17 00:00:00 2001
From: GuZheng <[email protected]>
Date: Tue, 23 Apr 2013 14:01:39 +0800
Subject: [PATCH v2 2/2] PCI: Convertalloc_pci_dev(void)topci_alloc_dev(bus)
instead
Quoted 6 lines
Use the new
pci_alloc_dev(bus)to replace the existing using ofalloc_pci_dev(void). And new functions pci_bus_get/put() are introdued to hidepci_bus' reference management.v2:
Follow Yinghai's suggestions to reducepci_bus' ref when destroying pci device. Add new functions pci_bus_get/put() to hidepci_bus' reference management.
You did not tell us if the remove test scripts works after put the line back.
If it does not work, what is the point of this patch?
Yinghai
Re: [PATCH v2 2/2] PCI: Convert alloc_pci_dev(void) to pci_alloc_dev(bus) instead
In reply to Jiang LiuQuoted 117 lines · Jiang Liu
Quoted 116 lines · Gu Zheng
From
b01e61759f894b651ed3bb39c9fc18e0b66d7cb3Mon Sep 17 00:00:00 2001
From: GuZheng <[email protected]>
Date: Tue, 23 Apr 2013 14:01:39 +0800
Subject: [PATCH v2 2/2] PCI: Convertalloc_pci_dev(void)topci_alloc_dev(bus)
insteadUse the new
pci_alloc_dev(bus)to replace the existing using ofalloc_pci_dev(void). And new functions pci_bus_get/put() are introdued to hidepci_bus' reference management.v2:
Follow Yinghai's suggestions to reducepci_bus' ref when destroying pci device. Add new functions pci_bus_get/put() to hidepci_bus' reference management.Signed-off-by Gu Zheng <[email protected]>--- arch/powerpc/kernel/pci_of_scan.c | 3 +-- arch/sparc/kernel/pci.c | 3 +-- drivers/char/agp/alpha-agp.c | 2 +- drivers/char/agp/parisc-agp.c | 2 +- drivers/pci/bus.c | 15 +++++++++++++++ drivers/pci/iov.c | 8 +++++--- drivers/pci/probe.c | 9 +++------ drivers/pci/remove.c | 2 ++ drivers/scsi/megaraid.c | 2 +- include/linux/pci.h | 3 +++ 10 files changed, 33 insertions(+), 16 deletions(-)arch/powerpc/kernel/pci_of_scan.c +1
-2@@ -128,7 +128,7 @@ struct pci_dev *of_create_pci_dev(struct device_node *node,const char *type;struct pci_slot *slot; - dev =alloc_pci_dev (); + dev =pci_alloc_dev (bus);if (!dev)return NULL ; type =of_get_property (node,"device_type" ,NULL );@@ -137,7 +137,6 @@ struct pci_dev *of_create_pci_dev(struct device_node *node,pr_debug (" create device, devfn: %x, type: %s\n" , devfn, type); - dev->bus = bus; dev->dev.of_node =of_node_get (node); dev->dev.parent = bus->bridge; dev->dev.bus = &pci_bus_type;arch/sparc/kernel/pci.c +1
-2@@ -254,7 +254,7 @@ static struct pci_dev *of_create_pci_dev(struct pci_pbm_info *pbm,const char *type;u32 class; - dev =alloc_pci_dev (); + dev =pci_alloc_dev (bus);if (!dev)return NULL ;@@ -281,7 +281,6 @@ static struct pci_dev *of_create_pci_dev(struct pci_pbm_info *pbm,printk (" create device, devfn: %x, type: %s\n" , devfn, type); - dev->bus = bus; dev->sysdata = node; dev->dev.parent = bus->bridge; dev->dev.bus = &pci_bus_type;drivers/char/agp/alpha-agp.c +1
-1@@ -174,7 +174,7 @@ alpha_core_agp_setup(void)/* * Build a fake pci_dev struct */ - pdev =alloc_pci_dev (); + pdev =pci_alloc_dev (NULL );if (!pdev)return -ENOMEM ; pdev->vendor =0xffff ;drivers/char/agp/parisc-agp.c +1
-1@@ -333,7 +333,7 @@ parisc_agp_setup(void __iomem *ioc_hpa, void __iomem *lba_hpa)struct agp_bridge_data *bridge;int error =0 ; - fake_bridge_dev =alloc_pci_dev (); + fake_bridge_dev =pci_alloc_dev (NULL );if (!fake_bridge_dev) { error = -ENOMEM ; goto fail;drivers/pci/bus.c +13
-0@@ -18,6 +18,21 @@#include "pci.h" +struct pci_bus *pci_bus_get (struct pci_bus *bus) +{ +if (bus) +get_device (&bus->dev); +return bus; +} +EXPORT_SYMBOL (pci_bus_get); + +void pci_bus_put (struct pci_bus *bus) +{ +if (bus) +put_device (&bus->dev); +}
Quoted 8 lines
drivers/pci/bus.c line 38
Quoted 5 lines
drivers/pci/bus.c +2
-0+EXPORT_SYMBOL (pci_bus_put); +void pci_add_resource_offset (struct list_head *resources,struct resource *res,resource_size_t offset) {Hi Zheng,
Could you please help to split addition ofpci_bus_get()andpci_bus_put()
into a separate patch? I'm working on some patches which depends on this.
Sure, a glad thing that it is also useful to you!:)
Quoted 35 lines
Quoted 35 lines
drivers/pci/iov.c +5
-3@@ -75,18 +75,20 @@ static int virtfn_add(struct pci_dev *dev, int id, int reset)struct pci_dev *virtfn;struct resource *res;struct pci_sriov *iov = dev->sriov; +struct pci_bus *bus; - virtfn =alloc_pci_dev (); + virtfn =pci_alloc_dev (NULL );if (!virtfn)return -ENOMEM ;mutex_lock (&iov->dev->sriov->lock); - virtfn->bus =virtfn_add_bus (dev->bus,virtfn_bus (dev, id)); -if (!virtfn->bus) { + bus =virtfn_add_bus (dev->bus,virtfn_bus (dev, id)); +if (!bus) {kfree (virtfn);mutex_unlock (&iov->dev->sriov->lock);return -ENOMEM ; } + virtfn->bus =pci_bus_get (bus); virtfn->devfn =virtfn_devfn (dev, id); virtfn->vendor = dev->vendor;pci_read_config_word (dev, iov->pos +PCI_SRIOV_VF_DID , &virtfn->device);drivers/pci/probe.c +0
-0@@ -1209,10 +1209,8 @@ struct pci_dev *pci_alloc_dev(struct pci_bus *bus)
Quoted 8 lines
drivers/pci/probe.c struct pci_dev *pci_alloc_dev(struct pci_bus *bus) · line 1212
Quoted 7 lines
drivers/pci/probe.c +1
-4INIT_LIST_HEAD (&dev->bus_list); -if (bus) { -get_device (&bus->dev); - dev->bus = bus; - } +if (bus)How about remove above redundant check?
Thanks for your review.
Yeah, the pre-check seems redundant, but I think it can avoid the meaningless calling pci_bus_get() and setting dev->bus.
Best regards,
Gu
Quoted 61 lines
Quoted 59 lines
drivers/pci/probe.c +2
-2+ dev->bus =pci_bus_get (bus);return dev; }@@ -1272,11 +1270,10 @@ static struct pci_dev *pci_scan_device(struct pci_bus *bus, int devfn)if (!pci_bus_read_dev_vendor_id (bus, devfn, &l,60 *1000 ))return NULL ; - dev =alloc_pci_dev (); + dev =pci_alloc_dev (bus);if (!dev)return NULL ; - dev->bus = bus; dev->devfn = devfn; dev->vendor = l &0xffff ; dev->device = (l >>16 ) &0xffff ;drivers/pci/remove.c +2
-0@@ -38,6 +38,8 @@ static void pci_destroy_dev(struct pci_dev *dev)list_del (&dev->bus_list);up_write (&pci_bus_sem); +pci_bus_put (dev->bus); +pci_free_resources (dev);put_device (&dev->dev); }drivers/scsi/megaraid.c +1
-1@@ -2025,7 +2025,7 @@ megaraid_abort_and_reset(adapter_t *adapter, Scsi_Cmnd *cmd, int aor)static inline int make_local_pdev (adapter_t *adapter,struct pci_dev **pdev) { - *pdev =alloc_pci_dev (); + *pdev =pci_alloc_dev (NULL );if ( *pdev ==NULL )return -1 ;include/linux/pci.h +3
-0@@ -1002,6 +1002,9 @@ int pci_request_selected_regions_exclusive(struct pci_dev *, int, const char *);void pci_release_selected_regions (struct pci_dev *,int );/* drivers/pci/bus.c */ +extern struct pci_bus *pci_bus_get (struct pci_bus *bus); +extern void pci_bus_put (struct pci_bus *bus); +void pci_add_resource (struct list_head *resources,struct resource *res);void pci_add_resource_offset (struct list_head *resources,struct resource *res,resource_size_t offset);
Re: [PATCH v2 2/2] PCI: Convert alloc_pci_dev(void) to pci_alloc_dev(bus) instead
In reply to Yinghai LuQuoted 7 lines · Yinghai Lu
Quoted 6 lines · Gu Zheng
From
b01e61759f894b651ed3bb39c9fc18e0b66d7cb3Mon Sep 17 00:00:00 2001
From: GuZheng <[email protected]>
Date: Tue, 23 Apr 2013 14:01:39 +0800
Subject: [PATCH v2 2/2] PCI: Convertalloc_pci_dev(void)topci_alloc_dev(bus)
instead
Quoted 8 lines
Quoted 6 lines
Use the new
pci_alloc_dev(bus)to replace the existing using ofalloc_pci_dev(void). And new functions pci_bus_get/put() are introdued to hidepci_bus' reference management.v2:
Follow Yinghai's suggestions to reducepci_bus' ref when destroying pci device. Add new functions pci_bus_get/put() to hidepci_bus' reference management.You did not tell us if the remove test scripts works after put the line back.
Hi Yinghai,
As you know, I split this patch from the original bug-fix one, and this one is
not used to fix the bug we discussed. My test box is on the duty of other tests, I'll do the test and send out the result as soon as it is ready for me.
BTW, Could please split a while to answer the two questions I asked you yesterday?
Quoted 3 lines
If it does not work, what is the point of this patch?
I think the patch title and the change log can explain all. It introduce a new pci_alloc_dev(bus) to replace the alloc_pci_dev(), and add the pci_bus' reference management when we deal with its downstream pci devices.
Thanks,
Gu
Quoted 3 lines
Yinghai
PATCH v2 2/4 PCI: introduce pci_bus_get()/pci_bus_put() to hide pci_bus' reference management
In reply to Bjorn HelgaasQuoted 1 line
From
ff785e84afd2558dd52de8e73c4f75b7563a595bMon Sep 17 00:00:00 2001
From: Gu Zheng <[email protected]>
Date: Tue, 30 Apr 2013 17:22:02 +0900
Subject: [PATCH v2 2/4] PCI: introduce pci_bus_get()/pci_bus_put() to hide
pci_bus' reference management
--- drivers/pci/bus.c | 15 +++++++++++++++ include/linux/pci.h | 3 +++ 2 files changed, 18 insertions(+), 0 deletions(-)
drivers/pci/bus.c +15 -0
@@ -18,6 +18,21 @@#include "pci.h" +struct pci_bus *pci_bus_get (struct pci_bus *bus) +{ +if (bus) +get_device (&bus->dev); +return bus; +} +EXPORT_SYMBOL (pci_bus_get); + +void pci_bus_put (struct pci_bus *bus) +{ +if (bus) +put_device (&bus->dev); +} +EXPORT_SYMBOL (pci_bus_put); +void pci_add_resource_offset (struct list_head *resources,struct resource *res,resource_size_t offset) {
include/linux/pci.h +3 -0
@@ -1020,6 +1020,9 @@ int pci_request_selected_regions_exclusive(struct pci_dev *, int, const char *);void pci_release_selected_regions (struct pci_dev *,int );/* drivers/pci/bus.c */ +extern struct pci_bus *pci_bus_get (struct pci_bus *bus); +extern void pci_bus_put (struct pci_bus *bus); +void pci_add_resource (struct list_head *resources,struct resource *res);void pci_add_resource_offset (struct list_head *resources,struct resource *res,resource_size_t offset);
Signature · 1 line
1.7.7
PATCH v2 1/4 PCI: Introduce pci_alloc_dev(struct pci_bus*) to replace alloc_pci_dev()
In reply to Bjorn HelgaasQuoted 1 line
From
888e824c01f9c039622a2ab74c3df3b884fd7b12Mon Sep 17 00:00:00 2001
From: Gu Zheng <[email protected]>
Date: Mon, 22 Apr 2013 19:04:07 +0900
Subject: [PATCH v2 1/4] PCI: Introduce pci_alloc_dev(struct pci_bus*) to replace
alloc_pci_dev()
Now here we introduce a new struct pci_dev *pci_alloc_dev(struct pci_bus *bus) to replace alloc_pci_dev(). It take a "struct pci_bus *" argument, so we can alloc a pci device on a target pci bus, and it acquire the reference of the pci_bus.
We use pci_alloc_dev(NULL) to simplify the old alloc_pci_dev(), and keep it for a while but mark it as __deprecated.
--- drivers/pci/probe.c | 13 ++++++++++++- include/linux/pci.h | 4 +++- 2 files changed, 15 insertions(+), 2 deletions(-)
drivers/pci/probe.c +12 -1
@@ -1201,7 +1201,7 @@ static void pci_release_bus_bridge_dev(struct device *dev)kfree (bridge); } -struct pci_dev *alloc_pci_dev (void ) +struct pci_dev *pci_alloc_dev (struct pci_bus *bus) {struct pci_dev *dev;
@@ -1211,8 +1211,19 @@ struct pci_dev *alloc_pci_dev(void)INIT_LIST_HEAD (&dev->bus_list); +if (bus) { +get_device (&bus->dev); + dev->bus = bus; + } +return dev; } +EXPORT_SYMBOL (pci_alloc_dev); + +struct pci_dev *alloc_pci_dev (void ) +{ +return pci_alloc_dev (NULL ); +}EXPORT_SYMBOL (alloc_pci_dev); bool pci_bus_read_dev_vendor_id(struct pci_bus *bus, int devfn, u32 *l,
include/linux/pci.h +3 -1
@@ -364,7 +364,9 @@ static inline struct pci_dev *pci_physfn(struct pci_dev *dev)return dev; } -struct pci_dev *alloc_pci_dev (void ); +struct pci_dev *pci_alloc_dev (struct pci_bus *bus); + +__deprecated struct pci_dev *alloc_pci_dev (void );#define to_pci_dev (n) container_of(n, struct pci_dev, dev)#define for_each_pci_dev (d) while ((d = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, d)) != NULL)
Signature · 1 line
1.7.7
PATCH v2 3/4 PCI: Convert alloc_pci_dev(void) to pci_alloc_dev(bus) instead
In reply to Bjorn HelgaasQuoted 1 line
From
055d93b0e9a29f3786996f90b7893bd6eb4d244bMon Sep 17 00:00:00 2001
From: Gu Zheng <[email protected]>
Date: Tue, 30 Apr 2013 17:23:31 +0900
Subject: [PATCH v2 3/4] PCI: Convert alloc_pci_dev(void) to pci_alloc_dev(bus)
instead
Use the new pci_alloc_dev(bus) to replace the existing using of alloc_pci_dev(void). And new functions pci_bus_get/put() are introdued to hide pci_bus' reference management.
v2:
Follow Bjorn's correction to move pci_bus_put() to pci_release_dev() instead.
--- arch/powerpc/kernel/pci_of_scan.c | 3 +-- arch/sparc/kernel/pci.c | 3 +-- drivers/char/agp/alpha-agp.c | 2 +- drivers/char/agp/parisc-agp.c | 2 +- drivers/pci/iov.c | 8 +++++--- drivers/pci/probe.c | 10 ++++------ drivers/scsi/megaraid.c | 2 +- 7 files changed, 14 insertions(+), 16 deletions(-)
arch/powerpc/kernel/pci_of_scan.c +1 -2
@@ -128,7 +128,7 @@ struct pci_dev *of_create_pci_dev(struct device_node *node,const char *type;struct pci_slot *slot; - dev =alloc_pci_dev (); + dev =pci_alloc_dev (bus);if (!dev)return NULL ; type =of_get_property (node,"device_type" ,NULL );
@@ -137,7 +137,6 @@ struct pci_dev *of_create_pci_dev(struct device_node *node,pr_debug (" create device, devfn: %x, type: %s\n" , devfn, type); - dev->bus = bus; dev->dev.of_node =of_node_get (node); dev->dev.parent = bus->bridge; dev->dev.bus = &pci_bus_type;
arch/sparc/kernel/pci.c +1 -2
@@ -254,7 +254,7 @@ static struct pci_dev *of_create_pci_dev(struct pci_pbm_info *pbm,const char *type;u32 class; - dev =alloc_pci_dev (); + dev =pci_alloc_dev (bus);if (!dev)return NULL ;
@@ -281,7 +281,6 @@ static struct pci_dev *of_create_pci_dev(struct pci_pbm_info *pbm,printk (" create device, devfn: %x, type: %s\n" , devfn, type); - dev->bus = bus; dev->sysdata = node; dev->dev.parent = bus->bridge; dev->dev.bus = &pci_bus_type;
drivers/char/agp/alpha-agp.c +1 -1
@@ -174,7 +174,7 @@ alpha_core_agp_setup(void)/* * Build a fake pci_dev struct */ - pdev =alloc_pci_dev (); + pdev =pci_alloc_dev (NULL );if (!pdev)return -ENOMEM ; pdev->vendor =0xffff ;
drivers/char/agp/parisc-agp.c +1 -1
@@ -333,7 +333,7 @@ parisc_agp_setup(void __iomem *ioc_hpa, void __iomem *lba_hpa)struct agp_bridge_data *bridge;int error =0 ; - fake_bridge_dev =alloc_pci_dev (); + fake_bridge_dev =pci_alloc_dev (NULL );if (!fake_bridge_dev) { error = -ENOMEM ; goto fail;
drivers/pci/iov.c +5 -3
@@ -75,18 +75,20 @@ static int virtfn_add(struct pci_dev *dev, int id, int reset)struct pci_dev *virtfn;struct resource *res;struct pci_sriov *iov = dev->sriov; +struct pci_bus *bus; - virtfn =alloc_pci_dev (); + virtfn =pci_alloc_dev (NULL );if (!virtfn)return -ENOMEM ;mutex_lock (&iov->dev->sriov->lock); - virtfn->bus =virtfn_add_bus (dev->bus,virtfn_bus (dev, id)); -if (!virtfn->bus) { + bus =virtfn_add_bus (dev->bus,virtfn_bus (dev, id)); +if (!bus) {kfree (virtfn);mutex_unlock (&iov->dev->sriov->lock);return -ENOMEM ; } + virtfn->bus =pci_bus_get (bus); virtfn->devfn =virtfn_devfn (dev, id); virtfn->vendor = dev->vendor;pci_read_config_word (dev, iov->pos +PCI_SRIOV_VF_DID , &virtfn->device);
drivers/pci/probe.c +4 -6
@@ -1131,6 +1131,7 @@ static void pci_release_dev(struct device *dev)struct pci_dev *pci_dev; pci_dev =to_pci_dev (dev); +pci_bus_put (pci_dev->bus);pci_release_capabilities (pci_dev);pci_release_of_node (pci_dev);kfree (pci_dev);
@@ -1211,10 +1212,8 @@ struct pci_dev *pci_alloc_dev(struct pci_bus *bus)INIT_LIST_HEAD (&dev->bus_list); -if (bus) { -get_device (&bus->dev); - dev->bus = bus; - } +if (bus) + dev->bus =pci_bus_get (bus);return dev; }
@@ -1274,11 +1273,10 @@ static struct pci_dev *pci_scan_device(struct pci_bus *bus, int devfn)if (!pci_bus_read_dev_vendor_id (bus, devfn, &l,60 *1000 ))return NULL ; - dev =alloc_pci_dev (); + dev =pci_alloc_dev (bus);if (!dev)return NULL ; - dev->bus = bus; dev->devfn = devfn; dev->vendor = l &0xffff ; dev->device = (l >>16 ) &0xffff ;
drivers/scsi/megaraid.c +1 -1
@@ -2025,7 +2025,7 @@ megaraid_abort_and_reset(adapter_t *adapter, Scsi_Cmnd *cmd, int aor)static inline int make_local_pdev (adapter_t *adapter,struct pci_dev **pdev) { - *pdev =alloc_pci_dev (); + *pdev =pci_alloc_dev (NULL );if ( *pdev ==NULL )return -1 ;
Signature · 1 line
1.7.7
PATCH v2 4/4 PCI: Check if the pci device get removed from pci tree already in remove_callback()
In reply to Bjorn HelgaasQuoted 1 line
From
a870da3615988f53a8949e5f8c907b079162067bMon Sep 17 00:00:00 2001
From: Gu Zheng <[email protected]>
Date: Tue, 30 Apr 2013 18:45:12 +0800
Subject: [PATCH v2 4/4] PCI: Check if the pci device get removed from pci tree already in remove_callback We found nested removing through:
echo -n 1 > /sys/bus/pci/devices/0000\:10\:00.0/remove ; echo -n 1 >
/sys/bus/pci/devices/0000\:1a\:01.0/remove
will cause kernel crash as bus get freed.
[ 418.946462] CPU 4 [ 418.968377] Pid: 512, comm: kworker/u:2 Tainted: G W 3.8.0 #2 FUJITSU-SV PRIMEQUEST 1800E/SB [ 419.081763] RIP: 0010:[<ffffffff8137972e>] [<ffffffff8137972e>] pci_bus_read_config_word+0x5e/0x90 [ 420.494137] Call Trace: [ 420.523326] [<ffffffff813851ef>] ? remove_callback+0x1f/0x40 [ 420.591984] [<ffffffff8138044b>] pci_pme_active+0x4b/0x1c0 [ 420.658545] [<ffffffff8137d8e7>] pci_stop_bus_device+0x57/0xb0 [ 420.729259] [<ffffffff8137dab6>] pci_stop_and_remove_bus_device+0x16/0x30 [ 420.811392] [<ffffffff813851fb>] remove_callback+0x2b/0x40 [ 420.877955] [<ffffffff81257a56>] sysfs_schedule_callback_work+0x26/0x70
https://bugzilla.kernel.org/show_bug.cgi?id=54411
We have one patch that will let device hold bus ref to prevent it from being freed, but that will still generate warning.
------------[ cut here ]------------ WARNING: at lib/list_debug.c:53 __list_del_entry+0x63/0xd0() Hardware name: PRIMEQUEST 1800E list_del corruption, ffff8807d1b6c000->next is LIST_POISON1 (dead000000100100) Call Trace: [<ffffffff81056d4f>] warn_slowpath_common+0x7f/0xc0 [<ffffffff81056e46>] warn_slowpath_fmt+0x46/0x50 [<ffffffff81280b13>] __list_del_entry+0x63/0xd0 [<ffffffff81280b91>] list_del+0x11/0x40 [<ffffffff81298331>] pci_destroy_dev+0x31/0xc0 [<ffffffff812985bb>] pci_remove_bus_device+0x5b/0x70 [<ffffffff812985ee>] pci_stop_and_remove_bus_device+0x1e/0x30 [<ffffffff8129fc89>] remove_callback+0x29/0x40 [<ffffffff811f3b84>] sysfs_schedule_callback_work+0x24/0x70
We can just check if the device get removed from pci tree already in the protection under pci_remove_rescan_mutex.
--- drivers/pci/pci-sysfs.c | 13 ++++++++++--- 1 files changed, 10 insertions(+), 3 deletions(-)
drivers/pci/pci-sysfs.c +10 -3
@@ -328,10 +328,17 @@ dev_rescan_store(struct device *dev, struct device_attribute *attr,static void remove_callback (struct device *dev) { -struct pci_dev *pdev =to_pci_dev (dev); - +struct pci_dev *pdev =to_pci_dev (dev), *tmp; +bool found = false; +struct pci_bus *bus = pdev->bus;mutex_lock (&pci_remove_rescan_mutex); -pci_stop_and_remove_bus_device (pdev); +list_for_each_entry (tmp, &bus->devices, bus_list) +if (tmp == pdev) { + found = true; +break ; + } +if (found) +pci_stop_and_remove_bus_device (pdev);mutex_unlock (&pci_remove_rescan_mutex); }
Signature · 1 line
1.7.7
Bjorn Helgaas
maintainerRe: [PATCH v2 4/4] PCI: Check if the pci device get removed from pci tree already in remove_callback()
Quoted 65 lines · Gu Zheng
From
a870da3615988f53a8949e5f8c907b079162067bMon Sep 17 00:00:00 2001
From: Gu Zheng <[email protected]>
Date: Tue, 30 Apr 2013 18:45:12 +0800
Subject: [PATCH v2 4/4] PCI: Check if the pci device get removed from pci tree already inremove_callbackWe found nested removing through:echo -n 1 > /sys/bus/pci/devices/0000\:10\:00.0/remove ; echo -n 1 >/sys/bus/pci/devices/0000\:1a\:01.0/remove
will cause kernel crash as bus get freed.
[ 418.946462] CPU 4 [ 418.968377] Pid: 512, comm: kworker/u:2 Tainted: G W 3.8.0 #2 FUJITSU-SV PRIMEQUEST 1800E/SB [ 419.081763] RIP: 0010:[<ffffffff8137972e>] [<ffffffff8137972e>] pci_bus_read_config_word+0x5e/0x90 [ 420.494137] Call Trace: [ 420.523326] [<ffffffff813851ef>] ? remove_callback+0x1f/0x40 [ 420.591984] [<ffffffff8138044b>] pci_pme_active+0x4b/0x1c0 [ 420.658545] [<ffffffff8137d8e7>] pci_stop_bus_device+0x57/0xb0 [ 420.729259] [<ffffffff8137dab6>] pci_stop_and_remove_bus_device+0x16/0x30 [ 420.811392] [<ffffffff813851fb>] remove_callback+0x2b/0x40 [ 420.877955] [<ffffffff81257a56>] sysfs_schedule_callback_work+0x26/0x70https://bugzilla.kernel.org/show_bug.cgi?id=54411
We have one patch that will let device hold bus ref to prevent it from being freed, but that will still generate warning.
------------[ cut here ]------------ WARNING: at lib/list_debug.c:53 __list_del_entry+0x63/0xd0() Hardware name: PRIMEQUEST 1800E list_del corruption, ffff8807d1b6c000->next is LIST_POISON1 (dead000000100100) Call Trace: [<ffffffff81056d4f>] warn_slowpath_common+0x7f/0xc0 [<ffffffff81056e46>] warn_slowpath_fmt+0x46/0x50 [<ffffffff81280b13>] __list_del_entry+0x63/0xd0 [<ffffffff81280b91>] list_del+0x11/0x40 [<ffffffff81298331>] pci_destroy_dev+0x31/0xc0 [<ffffffff812985bb>] pci_remove_bus_device+0x5b/0x70 [<ffffffff812985ee>] pci_stop_and_remove_bus_device+0x1e/0x30 [<ffffffff8129fc89>] remove_callback+0x29/0x40 [<ffffffff811f3b84>] sysfs_schedule_callback_work+0x24/0x70We can just check if the device get removed from pci tree already in the protection under
pci_remove_rescan_mutex.Signed-off-by Gu Zheng <[email protected]>Signed-off-by Yinghai Lu <[email protected]>--- drivers/pci/pci-sysfs.c | 13 ++++++++++--- 1 files changed, 10 insertions(+), 3 deletions(-)drivers/pci/pci-sysfs.c +2
-2@@ -328,10 +328,17 @@ dev_rescan_store(struct device *dev, struct device_attribute *attr,static void remove_callback (struct device *dev) { -struct pci_dev *pdev =to_pci_dev (dev); - +struct pci_dev *pdev =to_pci_dev (dev), *tmp; +bool found = false;
drivers/pci/pci-sysfs.c dev_rescan_store(struct device *dev, struct device_attribute *attr, · line 341
Quoted 10 lines
drivers/pci/pci-sysfs.c +8
-1+struct pci_bus *bus = pdev->bus;mutex_lock (&pci_remove_rescan_mutex); -pci_stop_and_remove_bus_device (pdev); +list_for_each_entry (tmp, &bus->devices, bus_list) +if (tmp == pdev) { + found = true; +break ; + } +if (found) +pci_stop_and_remove_bus_device (pdev);
I assume this series won't be needed when we eventually get the reference counting sorted out, because we shouldn't have to check whether the device still exists. Yinghai posted a "fix_racing_removing_5.patch", which currently doesn't apply cleanly, but I assume he'll refresh it after v3.10-rc1 is out.
Bjorn
Quoted 6 lines
drivers/pci/pci-sysfs.c +0
-1mutex_unlock (&pci_remove_rescan_mutex); } --1.7.7
Re: [PATCH v2 4/4] PCI: Check if the pci device get removed from pci tree already in remove_callback()
Quoted 72 lines · Bjorn Helgaas
Quoted 71 lines · Gu Zheng
From
a870da3615988f53a8949e5f8c907b079162067bMon Sep 17 00:00:00 2001
From: Gu Zheng <[email protected]>
Date: Tue, 30 Apr 2013 18:45:12 +0800
Subject: [PATCH v2 4/4] PCI: Check if the pci device get removed from pci tree already inremove_callbackWe found nested removing through:echo -n 1 > /sys/bus/pci/devices/0000\:10\:00.0/remove ; echo -n 1 >/sys/bus/pci/devices/0000\:1a\:01.0/remove
will cause kernel crash as bus get freed.
[ 418.946462] CPU 4 [ 418.968377] Pid: 512, comm: kworker/u:2 Tainted: G W 3.8.0 #2 FUJITSU-SV PRIMEQUEST 1800E/SB [ 419.081763] RIP: 0010:[<ffffffff8137972e>] [<ffffffff8137972e>] pci_bus_read_config_word+0x5e/0x90 [ 420.494137] Call Trace: [ 420.523326] [<ffffffff813851ef>] ? remove_callback+0x1f/0x40 [ 420.591984] [<ffffffff8138044b>] pci_pme_active+0x4b/0x1c0 [ 420.658545] [<ffffffff8137d8e7>] pci_stop_bus_device+0x57/0xb0 [ 420.729259] [<ffffffff8137dab6>] pci_stop_and_remove_bus_device+0x16/0x30 [ 420.811392] [<ffffffff813851fb>] remove_callback+0x2b/0x40 [ 420.877955] [<ffffffff81257a56>] sysfs_schedule_callback_work+0x26/0x70https://bugzilla.kernel.org/show_bug.cgi?id=54411
We have one patch that will let device hold bus ref to prevent it from being freed, but that will still generate warning.
------------[ cut here ]------------ WARNING: at lib/list_debug.c:53 __list_del_entry+0x63/0xd0() Hardware name: PRIMEQUEST 1800E list_del corruption, ffff8807d1b6c000->next is LIST_POISON1 (dead000000100100) Call Trace: [<ffffffff81056d4f>] warn_slowpath_common+0x7f/0xc0 [<ffffffff81056e46>] warn_slowpath_fmt+0x46/0x50 [<ffffffff81280b13>] __list_del_entry+0x63/0xd0 [<ffffffff81280b91>] list_del+0x11/0x40 [<ffffffff81298331>] pci_destroy_dev+0x31/0xc0 [<ffffffff812985bb>] pci_remove_bus_device+0x5b/0x70 [<ffffffff812985ee>] pci_stop_and_remove_bus_device+0x1e/0x30 [<ffffffff8129fc89>] remove_callback+0x29/0x40 [<ffffffff811f3b84>] sysfs_schedule_callback_work+0x24/0x70We can just check if the device get removed from pci tree already in the protection under
pci_remove_rescan_mutex.Signed-off-by Gu Zheng <[email protected]>Signed-off-by Yinghai Lu <[email protected]>--- drivers/pci/pci-sysfs.c | 13 ++++++++++--- 1 files changed, 10 insertions(+), 3 deletions(-)drivers/pci/pci-sysfs.c +6
-3@@ -328,10 +328,17 @@ dev_rescan_store(struct device *dev, struct device_attribute *attr,static void remove_callback (struct device *dev) { -struct pci_dev *pdev =to_pci_dev (dev); - +struct pci_dev *pdev =to_pci_dev (dev), *tmp; +bool found = false; +struct pci_bus *bus = pdev->bus;mutex_lock (&pci_remove_rescan_mutex); -pci_stop_and_remove_bus_device (pdev); +list_for_each_entry (tmp, &bus->devices, bus_list) +if (tmp == pdev) { + found = true;
Quoted 8 lines
drivers/pci/pci-sysfs.c dev_rescan_store(struct device *dev, struct device_attribute *attr, · line 341
Quoted 4 lines
drivers/pci/pci-sysfs.c +4
-0+break ; + } +if (found) +pci_stop_and_remove_bus_device (pdev);I assume this series won't be needed when we eventually get the reference counting sorted out, because we shouldn't have to check whether the device still exists.
Yes, your are right! Thanks for your correction.
Quoted 3 lines
Yinghai posted a
"fix_racing_removing_5.patch", which currently doesn't apply cleanly, but I assume he'll refresh it after v3.10-rc1 is out.
OK, let's wait and see! :)
Best regards,
Gu
Quoted 10 lines
Bjorn
Quoted 6 lines
drivers/pci/pci-sysfs.c +0
-1mutex_unlock (&pci_remove_rescan_mutex); } --1.7.7