Skip to contentSkip to conversation

net: hplance: use devm in probe

PATCH New Rosen Penev 2 participants 2 messages Aug 8, 2024 – Aug 9, 2024

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 net: hplance: use devm in probe

Allows removal of the remove function as devm can handle the freeing of these resources.

---
 drivers/net/ethernet/amd/hplance.c | 33 +++++++-----------------------
 1 file changed, 7 insertions(+), 26 deletions(-)
drivers/net/ethernet/amd/hplance.c +7 -26
index df42294530cb..2ebf7cc9ab21 100644
@@ -49,7 +49,6 @@ struct hplance_private {
  */
 static int hplance_init_one(struct dio_dev *d, const struct dio_device_id *ent);
 static void hplance_init(struct net_device *dev, struct dio_dev *d);
-static void hplance_remove_one(struct dio_dev *d);
 static void hplance_writerap(void *priv, unsigned short value);
 static void hplance_writerdp(void *priv, unsigned short value);
 static unsigned short hplance_readrdp(void *priv);
@@ -65,7 +64,6 @@ static struct dio_driver hplance_driver = {
 	.name      = "hplance",
 	.id_table  = hplance_dio_tbl,
 	.probe     = hplance_init_one,
-	.remove    = hplance_remove_one,
 };
 
 static const struct net_device_ops hplance_netdev_ops = {
@@ -84,21 +82,20 @@ static const struct net_device_ops hplance_netdev_ops = {
 static int hplance_init_one(struct dio_dev *d, const struct dio_device_id *ent)
 {
 	struct net_device *dev;
-	int err = -ENOMEM;
+	int err;
 
-	dev = alloc_etherdev(sizeof(struct hplance_private));
+	dev = devm_alloc_etherdev(sizeof(&d->dev, struct hplance_private));
 	if (!dev)
-		goto out;
+		return -ENOMEM;
 
-	err = -EBUSY;
-	if (!request_mem_region(dio_resource_start(d),
+	if (!devm_request_mem_region(&d->dev, dio_resource_start(d),
 				dio_resource_len(d), d->name))
-		goto out_free_netdev;
+		return -EBUSY;
 
 	hplance_init(dev, d);
-	err = register_netdev(dev);
+	err = devm_register_netdev(&d->dev, dev);
 	if (err)
-		goto out_release_mem_region;
+		return err;
 
 	dio_set_drvdata(d, dev);
 
@@ -106,22 +103,6 @@ static int hplance_init_one(struct dio_dev *d, const struct dio_device_id *ent)
 	       dev->name, d->name, d->scode, dev->dev_addr, d->ipl);
 
 	return 0;
-
- out_release_mem_region:
-	release_mem_region(dio_resource_start(d), dio_resource_len(d));
- out_free_netdev:
-	free_netdev(dev);
- out:
-	return err;
-}
-
-static void hplance_remove_one(struct dio_dev *d)
-{
-	struct net_device *dev = dio_get_drvdata(d);
-
-	unregister_netdev(dev);
-	release_mem_region(dio_resource_start(d), dio_resource_len(d));
-	free_netdev(dev);
 }
 
 /* Initialise a single lance board at the given DIO device */
Signature · 1 line
2.45.2
#1 lore raw
kernel test robot noticed the following build errors:

Hi Rosen,

kernel test robot noticed the following build errors:

[auto build test ERROR on net-next/main]

url:    https://github.com/intel-lab-lkp/linux/commits/Rosen-Penev/net-hplance-use-devm-in-probe/20240808-121217
base:   net-next/main
patch link:    https://lore.kernel.org/r/20240808041109.6871-1-rosenp%40gmail.com
patch subject: [PATCH net-next] net: hplance: use devm in probe
config: m68k-defconfig (https://download.01.org/0day-ci/archive/20240809/[email protected]/config)
compiler: m68k-linux-gcc (GCC) 14.1.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20240809/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All errors (new ones prefixed by >>):

drivers/net/ethernet/amd/hplance.c: In function 'hplance_init_one':

>> drivers/net/ethernet/amd/hplance.c:87:74: error: macro "devm_alloc_etherdev" requires 2 arguments, but only 1 given
      87 |         dev = devm_alloc_etherdev(sizeof(&d->dev, struct hplance_private));
         |                                                                          ^
   In file included from drivers/net/ethernet/amd/hplance.c:24:
   include/linux/etherdevice.h:64:9: note: macro "devm_alloc_etherdev" defined here
      64 | #define devm_alloc_etherdev(dev, sizeof_priv) devm_alloc_etherdev_mqs(dev, sizeof_priv, 1, 1)
         |         ^~~~~~~~~~~~~~~~~~~
>> drivers/net/ethernet/amd/hplance.c:87:15: error: 'devm_alloc_etherdev' undeclared (first use in this function); did you mean 'devm_alloc_etherdev_mqs'?
      87 |         dev = devm_alloc_etherdev(sizeof(&d->dev, struct hplance_private));
         |               ^~~~~~~~~~~~~~~~~~~
         |               devm_alloc_etherdev_mqs

drivers/net/ethernet/amd/hplance.c:87:15: note: each undeclared identifier is reported only once for each function it appears in

vim +/devm_alloc_etherdev +87 drivers/net/ethernet/amd/hplance.c

    80	
    81	/* Find all the HP Lance boards and initialise them... */
    82	static int hplance_init_one(struct dio_dev *d, const struct dio_device_id *ent)
    83	{
    84		struct net_device *dev;
    85		int err;
    86	
  > 87		dev = devm_alloc_etherdev(sizeof(&d->dev, struct hplance_private));
    88		if (!dev)
    89			return -ENOMEM;
    90	
    91		if (!devm_request_mem_region(&d->dev, dio_resource_start(d),
    92					dio_resource_len(d), d->name))
    93			return -EBUSY;
    94	
    95		hplance_init(dev, d);
    96		err = devm_register_netdev(&d->dev, dev);
    97		if (err)
    98			return err;
    99	

100 dio_set_drvdata(d, dev);
101
102 printk(KERN_INFO "%s: %s; select code %d, addr %pM, irq %d\n",
103 dev->name, d->name, d->scode, dev->dev_addr, d->ipl);
104
105 return 0;
106 }
107

Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki