Skip to contentSkip to conversation

drivers: misc: Directly use ida_alloc()/free()

PATCH New keliu 2 participants 3 messages May 27, 2022 – May 28, 2022

Subsystems (5)
lore
Share & tools
lore

keliu

author
#0 lore raw

PATCH 1/1 drivers: misc: Directly use ida_alloc()/free()

Use ida_alloc()/ida_free() instead of deprecated
ida_simple_get()/ida_simple_remove() .

---
 drivers/misc/bcm-vk/bcm_vk_dev.c | 6 +++---
 drivers/misc/dw-xdata-pcie.c     | 6 +++---
 drivers/misc/pci_endpoint_test.c | 6 +++---
 3 files changed, 9 insertions(+), 9 deletions(-)
drivers/misc/bcm-vk/bcm_vk_dev.c +3 -3
index a16b99bdaa13..a3a82ebbc699 100644
@@ -1401,7 +1401,7 @@ static int bcm_vk_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
 		bcm_vk_tty_set_irq_enabled(vk, i);
 	}
 
-	id = ida_simple_get(&bcm_vk_ida, 0, 0, GFP_KERNEL);
+	id = ida_alloc(&bcm_vk_ida, GFP_KERNEL);
 	if (id < 0) {
 		err = id;
 		dev_err(dev, "unable to get id\n");
@@ -1500,7 +1500,7 @@ static int bcm_vk_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
 	misc_device->name = NULL;
 
 err_ida_remove:
-	ida_simple_remove(&bcm_vk_ida, id);
+	ida_free(&bcm_vk_ida, id);
 
 err_irq:
 	for (i = 0; i < vk->num_irqs; i++)
@@ -1573,7 +1573,7 @@ static void bcm_vk_remove(struct pci_dev *pdev)
 	if (misc_device->name) {
 		misc_deregister(misc_device);
 		kfree(misc_device->name);
-		ida_simple_remove(&bcm_vk_ida, vk->devid);
+		ida_free(&bcm_vk_ida, vk->devid);
 	}
 	for (i = 0; i < vk->num_irqs; i++)
 		devm_free_irq(&pdev->dev, pci_irq_vector(pdev, i), vk);
drivers/misc/dw-xdata-pcie.c +3 -3
index 257c25da5199..59617d92a0a3 100644
@@ -333,7 +333,7 @@ static int dw_xdata_pcie_probe(struct pci_dev *pdev,
 
 	dw->pdev = pdev;
 
-	id = ida_simple_get(&xdata_ida, 0, 0, GFP_KERNEL);
+	id = ida_(&xdata_ida, GFP_KERNEL);
 	if (id < 0) {
 		dev_err(dev, "xData: unable to get id\n");
 		return id;
@@ -377,7 +377,7 @@ static int dw_xdata_pcie_probe(struct pci_dev *pdev,
 	kfree(dw->misc_dev.name);
 
 err_ida_remove:
-	ida_simple_remove(&xdata_ida, id);
+	ida_free(&xdata_ida, id);
 
 	return err;
 }
@@ -396,7 +396,7 @@ static void dw_xdata_pcie_remove(struct pci_dev *pdev)
 	dw_xdata_stop(dw);
 	misc_deregister(&dw->misc_dev);
 	kfree(dw->misc_dev.name);
-	ida_simple_remove(&xdata_ida, id);
+	ida_free(&xdata_ida, id);
 }
 
 static const struct pci_device_id dw_xdata_pcie_id_table[] = {
drivers/misc/pci_endpoint_test.c +3 -3
index 8f786a225dcf..d909a3f94566 100644
@@ -838,7 +838,7 @@ static int pci_endpoint_test_probe(struct pci_dev *pdev,
 
 	pci_set_drvdata(pdev, test);
 
-	id = ida_simple_get(&pci_endpoint_test_ida, 0, 0, GFP_KERNEL);
+	id = ida_alloc(&pci_endpoint_test_ida, GFP_KERNEL);
 	if (id < 0) {
 		err = id;
 		dev_err(dev, "Unable to get id\n");
@@ -885,7 +885,7 @@ static int pci_endpoint_test_probe(struct pci_dev *pdev,
 	kfree(test->name);
 
 err_ida_remove:
-	ida_simple_remove(&pci_endpoint_test_ida, id);
+	ida_free(&pci_endpoint_test_ida, id);
 
 err_iounmap:
 	for (bar = 0; bar < PCI_STD_NUM_BARS; bar++) {
@@ -918,7 +918,7 @@ static void pci_endpoint_test_remove(struct pci_dev *pdev)
 	misc_deregister(&test->miscdev);
 	kfree(misc_device->name);
 	kfree(test->name);
-	ida_simple_remove(&pci_endpoint_test_ida, id);
+	ida_free(&pci_endpoint_test_ida, id);
 	for (bar = 0; bar < PCI_STD_NUM_BARS; bar++) {
 		if (test->bar[bar])
 			pci_iounmap(pdev, test->bar[bar]);
Signature · 1 line
2.25.1
#1 lore raw
Thank you for the patch! Yet something to improve:

Hi keliu,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on char-misc/char-misc-testing]
[also build test ERROR on v5.18 next-20220527]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/intel-lab-lkp/linux/commits/keliu/drivers-misc-Directly-use-ida_alloc-free/20220527-162050
base:   https://git.kernel.org/pub/scm/linux/kernel/git/gregkh/char-misc.git 90de6805267f8c79cd2b1a36805071e257c39b5c
config: i386-randconfig-a001 (https://download.01.org/0day-ci/archive/20220528/[email protected]/config)
compiler: gcc-11 (Debian 11.3.0-1) 11.3.0
reproduce (this is a W=1 build):
        # https://github.com/intel-lab-lkp/linux/commit/f8f84e5642ea1ff2fb220c002a35c7d74ec14323
        git remote add linux-review https://github.com/intel-lab-lkp/linux
        git fetch --no-tags linux-review keliu/drivers-misc-Directly-use-ida_alloc-free/20220527-162050
        git checkout f8f84e5642ea1ff2fb220c002a35c7d74ec14323
        # save the config file
        mkdir build_dir && cp config build_dir/.config
        make W=1 O=build_dir ARCH=i386 SHELL=/bin/bash

If you fix the issue, kindly add following tag where applicable

All errors (new ones prefixed by >>):

drivers/misc/dw-xdata-pcie.c: In function 'dw_xdata_pcie_probe':

>> drivers/misc/dw-xdata-pcie.c:336:14: error: implicit declaration of function 'ida_' [-Werror=implicit-function-declaration]
     336 |         id = ida_(&xdata_ida, GFP_KERNEL);
         |              ^~~~

cc1: some warnings being treated as errors

vim +/ida_ +336 drivers/misc/dw-xdata-pcie.c

287
288 static int dw_xdata_pcie_probe(struct pci_dev *pdev,
289 const struct pci_device_id *pid)
290 {
291 struct device *dev = &pdev->dev;
292 struct dw_xdata *dw;
293 char name[24];
294 u64 addr;
295 int err;
296 int id;
297
298 /* Enable PCI device */
299 err = pcim_enable_device(pdev);
300 if (err) {
301 dev_err(dev, "enabling device failed\n");
302 return err;
303 }
304
305 /* Mapping PCI BAR regions */
306 err = pcim_iomap_regions(pdev, BIT(BAR_0), pci_name(pdev));
307 if (err) {
308 dev_err(dev, "xData BAR I/O remapping failed\n");
309 return err;
310 }
311
312 pci_set_master(pdev);
313
314 /* Allocate memory */
315 dw = devm_kzalloc(dev, sizeof(*dw), GFP_KERNEL);
316 if (!dw)
317 return -ENOMEM;
318
319 /* Data structure initialization */
320 mutex_init(&dw->mutex);
321
322 dw->rg_region.vaddr = pcim_iomap_table(pdev)[BAR_0];
323 if (!dw->rg_region.vaddr)
324 return -ENOMEM;
325
326 dw->rg_region.paddr = pdev->resource[BAR_0].start;
327
328 dw->max_wr_len = pcie_get_mps(pdev);
329 dw->max_wr_len >>= 2;
330
331 dw->max_rd_len = pcie_get_readrq(pdev);
332 dw->max_rd_len >>= 2;
333
334 dw->pdev = pdev;
335

 > 336		id = ida_(&xdata_ida, GFP_KERNEL);

337 if (id < 0) {
338 dev_err(dev, "xData: unable to get id\n");
339 return id;
340 }
341
342 snprintf(name, sizeof(name), DW_XDATA_DRIVER_NAME ".%d", id);
343 dw->misc_dev.name = kstrdup(name, GFP_KERNEL);
344 if (!dw->misc_dev.name) {
345 err = -ENOMEM;
346 goto err_ida_remove;
347 }
348
349 dw->misc_dev.minor = MISC_DYNAMIC_MINOR;
350 dw->misc_dev.parent = dev;
351 dw->misc_dev.groups = xdata_groups;
352
353 writel(0x0, &(__dw_regs(dw)->RAM_addr));
354 writel(0x0, &(__dw_regs(dw)->RAM_port));
355
356 addr = dw->rg_region.paddr + DW_XDATA_EP_MEM_OFFSET;
357 writel(lower_32_bits(addr), &(__dw_regs(dw)->addr_lsb));
358 writel(upper_32_bits(addr), &(__dw_regs(dw)->addr_msb));
359 dev_dbg(dev, "xData: target address = 0x%.16llx\n", addr);
360
361 dev_dbg(dev, "xData: wr_len = %zu, rd_len = %zu\n",
362 dw->max_wr_len * 4, dw->max_rd_len * 4);
363
364 /* Saving data structure reference */
365 pci_set_drvdata(pdev, dw);
366
367 /* Register misc device */
368 err = misc_register(&dw->misc_dev);
369 if (err) {
370 dev_err(dev, "xData: failed to register device\n");
371 goto err_kfree_name;
372 }
373
374 return 0;
375
376 err_kfree_name:
377 kfree(dw->misc_dev.name);
378
379 err_ida_remove:
380 ida_free(&xdata_ida, id);
381
382 return err;
383 }
384

Signature · 2 lines
0-DAY CI Kernel Test Service
https://01.org/lkp
#2 lore raw
In reply to keliu
Thank you for the patch! Yet something to improve:

Hi keliu,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on char-misc/char-misc-testing]
[also build test ERROR on v5.18 next-20220527]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/intel-lab-lkp/linux/commits/keliu/drivers-misc-Directly-use-ida_alloc-free/20220527-162050
base:   https://git.kernel.org/pub/scm/linux/kernel/git/gregkh/char-misc.git 90de6805267f8c79cd2b1a36805071e257c39b5c
config: x86_64-randconfig-a005 (https://download.01.org/0day-ci/archive/20220528/[email protected]/config)
compiler: clang version 15.0.0 (https://github.com/llvm/llvm-project 134d7f9a4b97e9035150d970bd9e376043c4577e)

reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# https://github.com/intel-lab-lkp/linux/commit/f8f84e5642ea1ff2fb220c002a35c7d74ec14323
git remote add linux-review https://github.com/intel-lab-lkp/linux
git fetch --no-tags linux-review keliu/drivers-misc-Directly-use-ida_alloc-free/20220527-162050 git checkout f8f84e5642ea1ff2fb220c002a35c7d74ec14323
# save the config file
mkdir build_dir && cp config build_dir/.config
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=x86_64 SHELL=/bin/bash drivers/

If you fix the issue, kindly add following tag where applicable

All errors (new ones prefixed by >>):

>> drivers/misc/dw-xdata-pcie.c:336:7: error: call to undeclared function 'ida_'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
           id = ida_(&xdata_ida, GFP_KERNEL);
                ^

1 error generated.

vim +/ida_ +336 drivers/misc/dw-xdata-pcie.c

287
288 static int dw_xdata_pcie_probe(struct pci_dev *pdev,
289 const struct pci_device_id *pid)
290 {
291 struct device *dev = &pdev->dev;
292 struct dw_xdata *dw;
293 char name[24];
294 u64 addr;
295 int err;
296 int id;
297
298 /* Enable PCI device */
299 err = pcim_enable_device(pdev);
300 if (err) {
301 dev_err(dev, "enabling device failed\n");
302 return err;
303 }
304
305 /* Mapping PCI BAR regions */
306 err = pcim_iomap_regions(pdev, BIT(BAR_0), pci_name(pdev));
307 if (err) {
308 dev_err(dev, "xData BAR I/O remapping failed\n");
309 return err;
310 }
311
312 pci_set_master(pdev);
313
314 /* Allocate memory */
315 dw = devm_kzalloc(dev, sizeof(*dw), GFP_KERNEL);
316 if (!dw)
317 return -ENOMEM;
318
319 /* Data structure initialization */
320 mutex_init(&dw->mutex);
321
322 dw->rg_region.vaddr = pcim_iomap_table(pdev)[BAR_0];
323 if (!dw->rg_region.vaddr)
324 return -ENOMEM;
325
326 dw->rg_region.paddr = pdev->resource[BAR_0].start;
327
328 dw->max_wr_len = pcie_get_mps(pdev);
329 dw->max_wr_len >>= 2;
330
331 dw->max_rd_len = pcie_get_readrq(pdev);
332 dw->max_rd_len >>= 2;
333
334 dw->pdev = pdev;
335

 > 336		id = ida_(&xdata_ida, GFP_KERNEL);

337 if (id < 0) {
338 dev_err(dev, "xData: unable to get id\n");
339 return id;
340 }
341
342 snprintf(name, sizeof(name), DW_XDATA_DRIVER_NAME ".%d", id);
343 dw->misc_dev.name = kstrdup(name, GFP_KERNEL);
344 if (!dw->misc_dev.name) {
345 err = -ENOMEM;
346 goto err_ida_remove;
347 }
348
349 dw->misc_dev.minor = MISC_DYNAMIC_MINOR;
350 dw->misc_dev.parent = dev;
351 dw->misc_dev.groups = xdata_groups;
352
353 writel(0x0, &(__dw_regs(dw)->RAM_addr));
354 writel(0x0, &(__dw_regs(dw)->RAM_port));
355
356 addr = dw->rg_region.paddr + DW_XDATA_EP_MEM_OFFSET;
357 writel(lower_32_bits(addr), &(__dw_regs(dw)->addr_lsb));
358 writel(upper_32_bits(addr), &(__dw_regs(dw)->addr_msb));
359 dev_dbg(dev, "xData: target address = 0x%.16llx\n", addr);
360
361 dev_dbg(dev, "xData: wr_len = %zu, rd_len = %zu\n",
362 dw->max_wr_len * 4, dw->max_rd_len * 4);
363
364 /* Saving data structure reference */
365 pci_set_drvdata(pdev, dw);
366
367 /* Register misc device */
368 err = misc_register(&dw->misc_dev);
369 if (err) {
370 dev_err(dev, "xData: failed to register device\n");
371 goto err_kfree_name;
372 }
373
374 return 0;
375
376 err_kfree_name:
377 kfree(dw->misc_dev.name);
378
379 err_ida_remove:
380 ida_free(&xdata_ida, id);
381
382 return err;
383 }
384

Signature · 2 lines
0-DAY CI Kernel Test Service
https://01.org/lkp