linux-wireless.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] bcma: Use managed APIs
@ 2025-07-19 14:43 Salah Triki
  2025-07-19 15:52 ` [PATCH v2] " Salah Triki
  0 siblings, 1 reply; 6+ messages in thread
From: Salah Triki @ 2025-07-19 14:43 UTC (permalink / raw)
  To: Rafał Miłecki, linux-wireless, linux-kernel; +Cc: salah.triki

Replace pci_* with pcim_* and kzalloc() with devm_kzalloc() so that no
need to worry about freeing resources and disabling the device.

Signed-off-by: Salah Triki <salah.triki@gmail.com>
---
 drivers/bcma/host_pci.c | 39 ++++++++++++++-------------------------
 1 file changed, 14 insertions(+), 25 deletions(-)

diff --git a/drivers/bcma/host_pci.c b/drivers/bcma/host_pci.c
index 960632197b05..665990b8afb5 100644
--- a/drivers/bcma/host_pci.c
+++ b/drivers/bcma/host_pci.c
@@ -10,6 +10,7 @@
 #include <linux/bcma/bcma.h>
 #include <linux/pci.h>
 #include <linux/module.h>
+#include <linux/serdev.h>
 
 static void bcma_host_pci_switch_core(struct bcma_device *core)
 {
@@ -161,22 +162,23 @@ static int bcma_host_pci_probe(struct pci_dev *dev,
 			       const struct pci_device_id *id)
 {
 	struct bcma_bus *bus;
-	int err = -ENOMEM;
+	int err;
 	u32 val;
 
 	/* Alloc */
-	bus = kzalloc(sizeof(*bus), GFP_KERNEL);
+	bus = devm_kzalloc(&dev->dev, sizeof(*bus), GFP_KERNEL);
 	if (!bus)
-		goto out;
+		return -ENOMEM;
 
 	/* Basic PCI configuration */
-	err = pci_enable_device(dev);
+	err = pcim_enable_device(dev);
 	if (err)
-		goto err_kfree_bus;
+		return err;
 
-	err = pci_request_regions(dev, "bcma-pci-bridge");
+	err = pcim_request_all_regions(dev, "bcma-pci-bridge");
 	if (err)
-		goto err_pci_disable;
+		return err;
+
 	pci_set_master(dev);
 
 	/* Disable the RETRY_TIMEOUT register (0x41) to keep
@@ -188,17 +190,16 @@ static int bcma_host_pci_probe(struct pci_dev *dev,
 	/* SSB needed additional powering up, do we have any AMBA PCI cards? */
 	if (!pci_is_pcie(dev)) {
 		bcma_err(bus, "PCI card detected, they are not supported.\n");
-		err = -ENXIO;
-		goto err_pci_release_regions;
+		return -ENXIO;
 	}
 
 	bus->dev = &dev->dev;
 
 	/* Map MMIO */
 	err = -ENOMEM;
-	bus->mmio = pci_iomap(dev, 0, ~0UL);
+	bus->mmio = pcim_iomap(dev, 0, ~0UL);
 	if (!bus->mmio)
-		goto err_pci_release_regions;
+		return err;
 
 	/* Host specific */
 	bus->host_pci = dev;
@@ -214,7 +215,7 @@ static int bcma_host_pci_probe(struct pci_dev *dev,
 	/* Scan bus to find out generation of PCIe core */
 	err = bcma_bus_scan(bus);
 	if (err)
-		goto err_pci_unmap_mmio;
+		return err;
 
 	if (bcma_find_core(bus, BCMA_CORE_PCIE2))
 		bus->host_is_pcie2 = true;
@@ -226,19 +227,11 @@ static int bcma_host_pci_probe(struct pci_dev *dev,
 
 	pci_set_drvdata(dev, bus);
 
-out:
 	return err;
 
 err_unregister_cores:
 	bcma_unregister_cores(bus);
-err_pci_unmap_mmio:
-	pci_iounmap(dev, bus->mmio);
-err_pci_release_regions:
-	pci_release_regions(dev);
-err_pci_disable:
-	pci_disable_device(dev);
-err_kfree_bus:
-	kfree(bus);
+
 	return err;
 }
 
@@ -247,10 +240,6 @@ static void bcma_host_pci_remove(struct pci_dev *dev)
 	struct bcma_bus *bus = pci_get_drvdata(dev);
 
 	bcma_bus_unregister(bus);
-	pci_iounmap(dev, bus->mmio);
-	pci_release_regions(dev);
-	pci_disable_device(dev);
-	kfree(bus);
 }
 
 #ifdef CONFIG_PM_SLEEP
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH v2] bcma: Use managed APIs
  2025-07-19 14:43 [PATCH] bcma: Use managed APIs Salah Triki
@ 2025-07-19 15:52 ` Salah Triki
  2025-07-19 15:54   ` Johannes Berg
  0 siblings, 1 reply; 6+ messages in thread
From: Salah Triki @ 2025-07-19 15:52 UTC (permalink / raw)
  To: Rafał Miłecki, linux-wireless, linux-kernel; +Cc: salah.triki

Replace pci_* with pcim_* and kzalloc() with devm_kzalloc() so that no
need to worry about freeing resources and disabling the device.

Signed-off-by: Salah Triki <salah.triki@gmail.com>
---
Changes in v2:
    -Delete the inclusion of serdev.h since it is not needed

 drivers/bcma/host_pci.c | 38 +++++++++++++-------------------------
 1 file changed, 13 insertions(+), 25 deletions(-)

diff --git a/drivers/bcma/host_pci.c b/drivers/bcma/host_pci.c
index 960632197b05..8cdb546ce697 100644
--- a/drivers/bcma/host_pci.c
+++ b/drivers/bcma/host_pci.c
@@ -161,22 +161,23 @@ static int bcma_host_pci_probe(struct pci_dev *dev,
 			       const struct pci_device_id *id)
 {
 	struct bcma_bus *bus;
-	int err = -ENOMEM;
+	int err;
 	u32 val;
 
 	/* Alloc */
-	bus = kzalloc(sizeof(*bus), GFP_KERNEL);
+	bus = devm_kzalloc(&dev->dev, sizeof(*bus), GFP_KERNEL);
 	if (!bus)
-		goto out;
+		return -ENOMEM;
 
 	/* Basic PCI configuration */
-	err = pci_enable_device(dev);
+	err = pcim_enable_device(dev);
 	if (err)
-		goto err_kfree_bus;
+		return err;
 
-	err = pci_request_regions(dev, "bcma-pci-bridge");
+	err = pcim_request_all_regions(dev, "bcma-pci-bridge");
 	if (err)
-		goto err_pci_disable;
+		return err;
+
 	pci_set_master(dev);
 
 	/* Disable the RETRY_TIMEOUT register (0x41) to keep
@@ -188,17 +189,16 @@ static int bcma_host_pci_probe(struct pci_dev *dev,
 	/* SSB needed additional powering up, do we have any AMBA PCI cards? */
 	if (!pci_is_pcie(dev)) {
 		bcma_err(bus, "PCI card detected, they are not supported.\n");
-		err = -ENXIO;
-		goto err_pci_release_regions;
+		return -ENXIO;
 	}
 
 	bus->dev = &dev->dev;
 
 	/* Map MMIO */
 	err = -ENOMEM;
-	bus->mmio = pci_iomap(dev, 0, ~0UL);
+	bus->mmio = pcim_iomap(dev, 0, ~0UL);
 	if (!bus->mmio)
-		goto err_pci_release_regions;
+		return err;
 
 	/* Host specific */
 	bus->host_pci = dev;
@@ -214,7 +214,7 @@ static int bcma_host_pci_probe(struct pci_dev *dev,
 	/* Scan bus to find out generation of PCIe core */
 	err = bcma_bus_scan(bus);
 	if (err)
-		goto err_pci_unmap_mmio;
+		return err;
 
 	if (bcma_find_core(bus, BCMA_CORE_PCIE2))
 		bus->host_is_pcie2 = true;
@@ -226,19 +226,11 @@ static int bcma_host_pci_probe(struct pci_dev *dev,
 
 	pci_set_drvdata(dev, bus);
 
-out:
 	return err;
 
 err_unregister_cores:
 	bcma_unregister_cores(bus);
-err_pci_unmap_mmio:
-	pci_iounmap(dev, bus->mmio);
-err_pci_release_regions:
-	pci_release_regions(dev);
-err_pci_disable:
-	pci_disable_device(dev);
-err_kfree_bus:
-	kfree(bus);
+
 	return err;
 }
 
@@ -247,10 +239,6 @@ static void bcma_host_pci_remove(struct pci_dev *dev)
 	struct bcma_bus *bus = pci_get_drvdata(dev);
 
 	bcma_bus_unregister(bus);
-	pci_iounmap(dev, bus->mmio);
-	pci_release_regions(dev);
-	pci_disable_device(dev);
-	kfree(bus);
 }
 
 #ifdef CONFIG_PM_SLEEP
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH v2] bcma: Use managed APIs
  2025-07-19 15:52 ` [PATCH v2] " Salah Triki
@ 2025-07-19 15:54   ` Johannes Berg
  2025-07-19 16:19     ` [PATCH v3] " Salah Triki
  0 siblings, 1 reply; 6+ messages in thread
From: Johannes Berg @ 2025-07-19 15:54 UTC (permalink / raw)
  To: Salah Triki, Rafał Miłecki, linux-wireless,
	linux-kernel

On Sat, 2025-07-19 at 16:52 +0100, Salah Triki wrote:
> Replace pci_* with pcim_* and kzalloc() with devm_kzalloc() so that no
> need to worry about freeing resources and disabling the device.
> 

Please mention how you tested this? :)

johannes

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH v3] bcma: Use managed APIs
  2025-07-19 15:54   ` Johannes Berg
@ 2025-07-19 16:19     ` Salah Triki
  2025-07-19 17:21       ` Jeff Johnson
  0 siblings, 1 reply; 6+ messages in thread
From: Salah Triki @ 2025-07-19 16:19 UTC (permalink / raw)
  To: Johannes Berg, Rafał Miłecki, linux-wireless,
	linux-kernel
  Cc: salah.triki

Replace pci_* with pcim_* and kzalloc() with devm_kzalloc() so that no
need to worry about freeing resources and disabling the device.

Signed-off-by: Salah Triki <salah.triki@gmail.com>
Tested-by: Compile only
---
Changes in v3:
    -Add the tag Tested-by

Changes in v2:
    -Delete the inclusion of serdev.h since it is not needed

 drivers/bcma/host_pci.c | 38 +++++++++++++-------------------------
 1 file changed, 13 insertions(+), 25 deletions(-)

diff --git a/drivers/bcma/host_pci.c b/drivers/bcma/host_pci.c
index 960632197b05..8cdb546ce697 100644
--- a/drivers/bcma/host_pci.c
+++ b/drivers/bcma/host_pci.c
@@ -161,22 +161,23 @@ static int bcma_host_pci_probe(struct pci_dev *dev,
 			       const struct pci_device_id *id)
 {
 	struct bcma_bus *bus;
-	int err = -ENOMEM;
+	int err;
 	u32 val;
 
 	/* Alloc */
-	bus = kzalloc(sizeof(*bus), GFP_KERNEL);
+	bus = devm_kzalloc(&dev->dev, sizeof(*bus), GFP_KERNEL);
 	if (!bus)
-		goto out;
+		return -ENOMEM;
 
 	/* Basic PCI configuration */
-	err = pci_enable_device(dev);
+	err = pcim_enable_device(dev);
 	if (err)
-		goto err_kfree_bus;
+		return err;
 
-	err = pci_request_regions(dev, "bcma-pci-bridge");
+	err = pcim_request_all_regions(dev, "bcma-pci-bridge");
 	if (err)
-		goto err_pci_disable;
+		return err;
+
 	pci_set_master(dev);
 
 	/* Disable the RETRY_TIMEOUT register (0x41) to keep
@@ -188,17 +189,16 @@ static int bcma_host_pci_probe(struct pci_dev *dev,
 	/* SSB needed additional powering up, do we have any AMBA PCI cards? */
 	if (!pci_is_pcie(dev)) {
 		bcma_err(bus, "PCI card detected, they are not supported.\n");
-		err = -ENXIO;
-		goto err_pci_release_regions;
+		return -ENXIO;
 	}
 
 	bus->dev = &dev->dev;
 
 	/* Map MMIO */
 	err = -ENOMEM;
-	bus->mmio = pci_iomap(dev, 0, ~0UL);
+	bus->mmio = pcim_iomap(dev, 0, ~0UL);
 	if (!bus->mmio)
-		goto err_pci_release_regions;
+		return err;
 
 	/* Host specific */
 	bus->host_pci = dev;
@@ -214,7 +214,7 @@ static int bcma_host_pci_probe(struct pci_dev *dev,
 	/* Scan bus to find out generation of PCIe core */
 	err = bcma_bus_scan(bus);
 	if (err)
-		goto err_pci_unmap_mmio;
+		return err;
 
 	if (bcma_find_core(bus, BCMA_CORE_PCIE2))
 		bus->host_is_pcie2 = true;
@@ -226,19 +226,11 @@ static int bcma_host_pci_probe(struct pci_dev *dev,
 
 	pci_set_drvdata(dev, bus);
 
-out:
 	return err;
 
 err_unregister_cores:
 	bcma_unregister_cores(bus);
-err_pci_unmap_mmio:
-	pci_iounmap(dev, bus->mmio);
-err_pci_release_regions:
-	pci_release_regions(dev);
-err_pci_disable:
-	pci_disable_device(dev);
-err_kfree_bus:
-	kfree(bus);
+
 	return err;
 }
 
@@ -247,10 +239,6 @@ static void bcma_host_pci_remove(struct pci_dev *dev)
 	struct bcma_bus *bus = pci_get_drvdata(dev);
 
 	bcma_bus_unregister(bus);
-	pci_iounmap(dev, bus->mmio);
-	pci_release_regions(dev);
-	pci_disable_device(dev);
-	kfree(bus);
 }
 
 #ifdef CONFIG_PM_SLEEP
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH v3] bcma: Use managed APIs
  2025-07-19 16:19     ` [PATCH v3] " Salah Triki
@ 2025-07-19 17:21       ` Jeff Johnson
  2025-07-19 18:38         ` Salah Triki
  0 siblings, 1 reply; 6+ messages in thread
From: Jeff Johnson @ 2025-07-19 17:21 UTC (permalink / raw)
  To: Salah Triki, Johannes Berg, Rafał Miłecki,
	linux-wireless, linux-kernel

On 7/19/2025 9:19 AM, Salah Triki wrote:
> Replace pci_* with pcim_* and kzalloc() with devm_kzalloc() so that no
> need to worry about freeing resources and disabling the device.
> 
> Signed-off-by: Salah Triki <salah.triki@gmail.com>
> Tested-by: Compile only

1) When you post a new version of a patch, please do NOT have it be
In-Reply-To any previous messages. Each version of a patch should start a
separate e-mail thread. The guidance at
<https://www.kernel.org/doc/html/latest/process/submitting-patches.html#explicit-in-reply-to-headers>
seems outdated.

2) Most maintainers will not accept patches which make such a big semantic
change without actually testing the change on hardware.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v3] bcma: Use managed APIs
  2025-07-19 17:21       ` Jeff Johnson
@ 2025-07-19 18:38         ` Salah Triki
  0 siblings, 0 replies; 6+ messages in thread
From: Salah Triki @ 2025-07-19 18:38 UTC (permalink / raw)
  To: Jeff Johnson
  Cc: Johannes Berg, Rafał Miłecki, linux-wireless,
	linux-kernel

On Sat, Jul 19, 2025 at 10:21:59AM -0700, Jeff Johnson wrote:
> 
> 1) When you post a new version of a patch, please do NOT have it be
> In-Reply-To any previous messages. Each version of a patch should start a
> separate e-mail thread. The guidance at
> <https://www.kernel.org/doc/html/latest/process/submitting-patches.html#explicit-in-reply-to-headers>
> seems outdated.
> 
> 2) Most maintainers will not accept patches which make such a big semantic
> change without actually testing the change on hardware.

Thanx for information

Best regards,
Salah Triki

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2025-07-19 18:38 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-07-19 14:43 [PATCH] bcma: Use managed APIs Salah Triki
2025-07-19 15:52 ` [PATCH v2] " Salah Triki
2025-07-19 15:54   ` Johannes Berg
2025-07-19 16:19     ` [PATCH v3] " Salah Triki
2025-07-19 17:21       ` Jeff Johnson
2025-07-19 18:38         ` Salah Triki

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).