public inbox for linux-acpi@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] ACPI: video: Replace backlight_device_register() with devm variant
@ 2025-10-07  3:07 Kaushlendra Kumar
  2025-10-10 10:18 ` kernel test robot
  0 siblings, 1 reply; 2+ messages in thread
From: Kaushlendra Kumar @ 2025-10-07  3:07 UTC (permalink / raw)
  To: rafael, lenb; +Cc: linux-acpi, Kaushlendra Kumar

Replace deprecated backlight_device_register() with
devm_backlight_device_register() to use device-managed
resource allocation. This automatically handles backlight
device cleanup when the device is removed, eliminating the
need for manual backlight_device_unregister() calls.

Remove the manual cleanup code in acpi_video_dev_unregister_backlight()
as the managed version handles deregistration automatically.

Signed-off-by: Kaushlendra Kumar <kaushlendra.kumar@intel.com>
---
 drivers/acpi/acpi_video.c | 19 +++++++------------
 1 file changed, 7 insertions(+), 12 deletions(-)

diff --git a/drivers/acpi/acpi_video.c b/drivers/acpi/acpi_video.c
index 103f29661576..e56665977ed7 100644
--- a/drivers/acpi/acpi_video.c
+++ b/drivers/acpi/acpi_video.c
@@ -1741,16 +1741,15 @@ static void acpi_video_dev_register_backlight(struct acpi_video_device *device)
 	props.type = BACKLIGHT_FIRMWARE;
 	props.max_brightness =
 		device->brightness->count - ACPI_VIDEO_FIRST_LEVEL - 1;
-	device->backlight = backlight_device_register(name,
-						      parent,
-						      device,
-						      &acpi_backlight_ops,
-						      &props);
+	device->backlight = devm_backlight_device_register(&pdev->dev,
+							  name,
+							  parent,
+							  device,
+							  &acpi_backlight_ops,
+							  &props);
 	kfree(name);
-	if (IS_ERR(device->backlight)) {
-		device->backlight = NULL;
+	if (IS_ERR(device->backlight))
 		return;
-	}
 
 	/*
 	 * Save current brightness level in case we have to restore it
@@ -1841,10 +1840,6 @@ static int acpi_video_bus_register_backlight(struct acpi_video_bus *video)
 
 static void acpi_video_dev_unregister_backlight(struct acpi_video_device *device)
 {
-	if (device->backlight) {
-		backlight_device_unregister(device->backlight);
-		device->backlight = NULL;
-	}
 	if (device->brightness) {
 		kfree(device->brightness->levels);
 		kfree(device->brightness);
-- 
2.34.1


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

* Re: [PATCH] ACPI: video: Replace backlight_device_register() with devm variant
  2025-10-07  3:07 [PATCH] ACPI: video: Replace backlight_device_register() with devm variant Kaushlendra Kumar
@ 2025-10-10 10:18 ` kernel test robot
  0 siblings, 0 replies; 2+ messages in thread
From: kernel test robot @ 2025-10-10 10:18 UTC (permalink / raw)
  To: Kaushlendra Kumar, rafael, lenb
  Cc: llvm, oe-kbuild-all, linux-acpi, Kaushlendra Kumar

Hi Kaushlendra,

kernel test robot noticed the following build warnings:

[auto build test WARNING on rafael-pm/linux-next]
[also build test WARNING on rafael-pm/bleeding-edge linus/master v6.17 next-20251009]
[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#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Kaushlendra-Kumar/ACPI-video-Replace-backlight_device_register-with-devm-variant/20251010-133230
base:   https://git.kernel.org/pub/scm/linux/kernel/git/rafael/linux-pm.git linux-next
patch link:    https://lore.kernel.org/r/20251007030730.3192901-1-kaushlendra.kumar%40intel.com
patch subject: [PATCH] ACPI: video: Replace backlight_device_register() with devm variant
config: i386-buildonly-randconfig-002-20251010 (https://download.01.org/0day-ci/archive/20251010/202510101817.Xkl2fc9D-lkp@intel.com/config)
compiler: clang version 20.1.8 (https://github.com/llvm/llvm-project 87f0227cb60147a26a1eeb4fb06e3b505e9c7261)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20251010/202510101817.Xkl2fc9D-lkp@intel.com/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 <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202510101817.Xkl2fc9D-lkp@intel.com/

All warnings (new ones prefixed by >>):

>> drivers/acpi/acpi_video.c:1732:6: warning: variable 'pdev' is used uninitialized whenever 'if' condition is false [-Wsometimes-uninitialized]
    1732 |         if (ACPI_SUCCESS(acpi_get_parent(device->dev->handle, &acpi_parent))) {
         |             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   include/acpi/acexcep.h:57:41: note: expanded from macro 'ACPI_SUCCESS'
      57 | #define ACPI_SUCCESS(a)                 (!(a))
         |                                         ^~~~~~
   drivers/acpi/acpi_video.c:1744:54: note: uninitialized use occurs here
    1744 |         device->backlight = devm_backlight_device_register(&pdev->dev,
         |                                                             ^~~~
   drivers/acpi/acpi_video.c:1732:2: note: remove the 'if' if its condition is always true
    1732 |         if (ACPI_SUCCESS(acpi_get_parent(device->dev->handle, &acpi_parent))) {
         |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   drivers/acpi/acpi_video.c:1716:22: note: initialize the variable 'pdev' to silence this warning
    1716 |         struct pci_dev *pdev;
         |                             ^
         |                              = NULL
   1 warning generated.


vim +1732 drivers/acpi/acpi_video.c

c504f8cb68eb0d drivers/acpi/video.c      Zhang Rui         2009-12-30  1712  
67b662e189f469 drivers/acpi/video.c      Aaron Lu          2013-10-11  1713  static void acpi_video_dev_register_backlight(struct acpi_video_device *device)
67b662e189f469 drivers/acpi/video.c      Aaron Lu          2013-10-11  1714  {
67b662e189f469 drivers/acpi/video.c      Aaron Lu          2013-10-11  1715  	struct backlight_properties props;
67b662e189f469 drivers/acpi/video.c      Aaron Lu          2013-10-11  1716  	struct pci_dev *pdev;
67b662e189f469 drivers/acpi/video.c      Aaron Lu          2013-10-11  1717  	acpi_handle acpi_parent;
67b662e189f469 drivers/acpi/video.c      Aaron Lu          2013-10-11  1718  	struct device *parent = NULL;
67b662e189f469 drivers/acpi/video.c      Aaron Lu          2013-10-11  1719  	int result;
67b662e189f469 drivers/acpi/video.c      Aaron Lu          2013-10-11  1720  	static int count;
67b662e189f469 drivers/acpi/video.c      Aaron Lu          2013-10-11  1721  	char *name;
67b662e189f469 drivers/acpi/video.c      Aaron Lu          2013-10-11  1722  
67b662e189f469 drivers/acpi/video.c      Aaron Lu          2013-10-11  1723  	result = acpi_video_init_brightness(device);
67b662e189f469 drivers/acpi/video.c      Aaron Lu          2013-10-11  1724  	if (result)
67b662e189f469 drivers/acpi/video.c      Aaron Lu          2013-10-11  1725  		return;
654a182d8562d5 drivers/acpi/video.c      Hans de Goede     2015-06-09  1726  
67b662e189f469 drivers/acpi/video.c      Aaron Lu          2013-10-11  1727  	name = kasprintf(GFP_KERNEL, "acpi_video%d", count);
67b662e189f469 drivers/acpi/video.c      Aaron Lu          2013-10-11  1728  	if (!name)
67b662e189f469 drivers/acpi/video.c      Aaron Lu          2013-10-11  1729  		return;
67b662e189f469 drivers/acpi/video.c      Aaron Lu          2013-10-11  1730  	count++;
67b662e189f469 drivers/acpi/video.c      Aaron Lu          2013-10-11  1731  
ccd45faf497374 drivers/acpi/acpi_video.c Nikita Kiryushin  2023-11-09 @1732  	if (ACPI_SUCCESS(acpi_get_parent(device->dev->handle, &acpi_parent))) {
67b662e189f469 drivers/acpi/video.c      Aaron Lu          2013-10-11  1733  		pdev = acpi_get_pci_dev(acpi_parent);
67b662e189f469 drivers/acpi/video.c      Aaron Lu          2013-10-11  1734  		if (pdev) {
67b662e189f469 drivers/acpi/video.c      Aaron Lu          2013-10-11  1735  			parent = &pdev->dev;
67b662e189f469 drivers/acpi/video.c      Aaron Lu          2013-10-11  1736  			pci_dev_put(pdev);
67b662e189f469 drivers/acpi/video.c      Aaron Lu          2013-10-11  1737  		}
ccd45faf497374 drivers/acpi/acpi_video.c Nikita Kiryushin  2023-11-09  1738  	}
67b662e189f469 drivers/acpi/video.c      Aaron Lu          2013-10-11  1739  
67b662e189f469 drivers/acpi/video.c      Aaron Lu          2013-10-11  1740  	memset(&props, 0, sizeof(struct backlight_properties));
67b662e189f469 drivers/acpi/video.c      Aaron Lu          2013-10-11  1741  	props.type = BACKLIGHT_FIRMWARE;
d485ef43072e54 drivers/acpi/acpi_video.c Dmitry Frank      2017-04-19  1742  	props.max_brightness =
d485ef43072e54 drivers/acpi/acpi_video.c Dmitry Frank      2017-04-19  1743  		device->brightness->count - ACPI_VIDEO_FIRST_LEVEL - 1;
ef5cc540f10200 drivers/acpi/acpi_video.c Kaushlendra Kumar 2025-10-07  1744  	device->backlight = devm_backlight_device_register(&pdev->dev,
ef5cc540f10200 drivers/acpi/acpi_video.c Kaushlendra Kumar 2025-10-07  1745  							  name,
67b662e189f469 drivers/acpi/video.c      Aaron Lu          2013-10-11  1746  							  parent,
67b662e189f469 drivers/acpi/video.c      Aaron Lu          2013-10-11  1747  							  device,
67b662e189f469 drivers/acpi/video.c      Aaron Lu          2013-10-11  1748  							  &acpi_backlight_ops,
67b662e189f469 drivers/acpi/video.c      Aaron Lu          2013-10-11  1749  							  &props);
67b662e189f469 drivers/acpi/video.c      Aaron Lu          2013-10-11  1750  	kfree(name);
ef5cc540f10200 drivers/acpi/acpi_video.c Kaushlendra Kumar 2025-10-07  1751  	if (IS_ERR(device->backlight))
67b662e189f469 drivers/acpi/video.c      Aaron Lu          2013-10-11  1752  		return;
67b662e189f469 drivers/acpi/video.c      Aaron Lu          2013-10-11  1753  
67b662e189f469 drivers/acpi/video.c      Aaron Lu          2013-10-11  1754  	/*
67b662e189f469 drivers/acpi/video.c      Aaron Lu          2013-10-11  1755  	 * Save current brightness level in case we have to restore it
67b662e189f469 drivers/acpi/video.c      Aaron Lu          2013-10-11  1756  	 * before acpi_video_device_lcd_set_level() is called next time.
67b662e189f469 drivers/acpi/video.c      Aaron Lu          2013-10-11  1757  	 */
67b662e189f469 drivers/acpi/video.c      Aaron Lu          2013-10-11  1758  	device->backlight->props.brightness =
67b662e189f469 drivers/acpi/video.c      Aaron Lu          2013-10-11  1759  			acpi_video_get_brightness(device->backlight);
67b662e189f469 drivers/acpi/video.c      Aaron Lu          2013-10-11  1760  
172c48caed91a9 drivers/acpi/acpi_video.c Hans de Goede     2023-11-27  1761  	device->cooling_dev = thermal_cooling_device_register("LCD", device,
172c48caed91a9 drivers/acpi/acpi_video.c Hans de Goede     2023-11-27  1762  							      &video_cooling_ops);
67b662e189f469 drivers/acpi/video.c      Aaron Lu          2013-10-11  1763  	if (IS_ERR(device->cooling_dev)) {
67b662e189f469 drivers/acpi/video.c      Aaron Lu          2013-10-11  1764  		/*
99678ed73a50d2 drivers/acpi/video.c      Hans de Goede     2014-05-15  1765  		 * Set cooling_dev to NULL so we don't crash trying to free it.
99678ed73a50d2 drivers/acpi/video.c      Hans de Goede     2014-05-15  1766  		 * Also, why the hell we are returning early and not attempt to
99678ed73a50d2 drivers/acpi/video.c      Hans de Goede     2014-05-15  1767  		 * register video output if cooling device registration failed?
67b662e189f469 drivers/acpi/video.c      Aaron Lu          2013-10-11  1768  		 * -- dtor
67b662e189f469 drivers/acpi/video.c      Aaron Lu          2013-10-11  1769  		 */
67b662e189f469 drivers/acpi/video.c      Aaron Lu          2013-10-11  1770  		device->cooling_dev = NULL;
67b662e189f469 drivers/acpi/video.c      Aaron Lu          2013-10-11  1771  		return;
67b662e189f469 drivers/acpi/video.c      Aaron Lu          2013-10-11  1772  	}
67b662e189f469 drivers/acpi/video.c      Aaron Lu          2013-10-11  1773  
67b662e189f469 drivers/acpi/video.c      Aaron Lu          2013-10-11  1774  	dev_info(&device->dev->dev, "registered as cooling_device%d\n",
67b662e189f469 drivers/acpi/video.c      Aaron Lu          2013-10-11  1775  		 device->cooling_dev->id);
67b662e189f469 drivers/acpi/video.c      Aaron Lu          2013-10-11  1776  	result = sysfs_create_link(&device->dev->dev.kobj,
67b662e189f469 drivers/acpi/video.c      Aaron Lu          2013-10-11  1777  			&device->cooling_dev->device.kobj,
67b662e189f469 drivers/acpi/video.c      Aaron Lu          2013-10-11  1778  			"thermal_cooling");
67b662e189f469 drivers/acpi/video.c      Aaron Lu          2013-10-11  1779  	if (result)
2924d2f837788b drivers/acpi/acpi_video.c Rafael J. Wysocki 2021-02-03  1780  		pr_info("sysfs link creation failed\n");
2924d2f837788b drivers/acpi/acpi_video.c Rafael J. Wysocki 2021-02-03  1781  
67b662e189f469 drivers/acpi/video.c      Aaron Lu          2013-10-11  1782  	result = sysfs_create_link(&device->cooling_dev->device.kobj,
67b662e189f469 drivers/acpi/video.c      Aaron Lu          2013-10-11  1783  			&device->dev->dev.kobj, "device");
67b662e189f469 drivers/acpi/video.c      Aaron Lu          2013-10-11  1784  	if (result)
2924d2f837788b drivers/acpi/acpi_video.c Rafael J. Wysocki 2021-02-03  1785  		pr_info("Reverse sysfs link creation failed\n");
67b662e189f469 drivers/acpi/video.c      Aaron Lu          2013-10-11  1786  }
67b662e189f469 drivers/acpi/video.c      Aaron Lu          2013-10-11  1787  

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

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

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

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-10-07  3:07 [PATCH] ACPI: video: Replace backlight_device_register() with devm variant Kaushlendra Kumar
2025-10-10 10:18 ` kernel test robot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox