diff mbox series

[v2] fbdev: lcdcfb: add missing device_remove_file()

Message ID 20250208092918.251733-1-oushixiong1025@163.com (mailing list archive)
State New
Headers show
Series [v2] fbdev: lcdcfb: add missing device_remove_file() | expand

Commit Message

Shixiong Ou Feb. 8, 2025, 9:29 a.m. UTC
From: Shixiong Ou <oushixiong@kylinos.cn>

1. The device_remove_file() need to be called when driver is removing.
2. The device_remove_file() need to be called if the call to
   device_create_file() fails.

Signed-off-by: Shixiong Ou <oushixiong@kylinos.cn>
---
v1->v2:
	add missing 'return error'.
	call device_remove_file() in sh_mobile_lcdc_overlay_fb_unregister().

 drivers/video/fbdev/sh_mobile_lcdcfb.c | 18 ++++++++++++++----
 1 file changed, 14 insertions(+), 4 deletions(-)

Comments

kernel test robot Feb. 19, 2025, 5:25 a.m. UTC | #1
Hi,

kernel test robot noticed the following build warnings:

[auto build test WARNING on lee-leds/for-leds-next]
[also build test WARNING on linus/master v6.14-rc3 next-20250218]
[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/oushixiong1025-163-com/fbdev-lcdcfb-add-missing-device_remove_file/20250208-173203
base:   https://git.kernel.org/pub/scm/linux/kernel/git/lee/leds.git for-leds-next
patch link:    https://lore.kernel.org/r/20250208092918.251733-1-oushixiong1025%40163.com
patch subject: [PATCH v2] fbdev: lcdcfb: add missing device_remove_file()
config: nios2-randconfig-r072-20250219 (https://download.01.org/0day-ci/archive/20250219/202502191200.AVwVc1DY-lkp@intel.com/config)
compiler: nios2-linux-gcc (GCC) 14.2.0

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/202502191200.AVwVc1DY-lkp@intel.com/

smatch warnings:
drivers/video/fbdev/sh_mobile_lcdcfb.c:1544 sh_mobile_lcdc_overlay_fb_register() warn: always true condition '(--i >= 0) => (0-u32max >= 0)'
drivers/video/fbdev/sh_mobile_lcdcfb.c:1544 sh_mobile_lcdc_overlay_fb_register() warn: always true condition '(--i >= 0) => (0-u32max >= 0)'
drivers/video/fbdev/sh_mobile_lcdcfb.c:2652 sh_mobile_lcdc_probe() warn: 'irq' from request_irq() not released on lines: 2652.
drivers/video/fbdev/sh_mobile_lcdcfb.c:2652 sh_mobile_lcdc_probe() warn: 'priv->base' from ioremap() not released on lines: 2652.

vim +1544 drivers/video/fbdev/sh_mobile_lcdcfb.c

  1517	
  1518	static int
  1519	sh_mobile_lcdc_overlay_fb_register(struct sh_mobile_lcdc_overlay *ovl)
  1520	{
  1521		struct sh_mobile_lcdc_priv *lcdc = ovl->channel->lcdc;
  1522		struct fb_info *info = ovl->info;
  1523		unsigned int i, error = 0;
  1524		int ret;
  1525	
  1526		if (info == NULL)
  1527			return 0;
  1528	
  1529		ret = register_framebuffer(info);
  1530		if (ret < 0)
  1531			return ret;
  1532	
  1533		dev_info(lcdc->dev, "registered %s/overlay %u as %dx%d %dbpp.\n",
  1534			 dev_name(lcdc->dev), ovl->index, info->var.xres,
  1535			 info->var.yres, info->var.bits_per_pixel);
  1536	
  1537		for (i = 0; i < ARRAY_SIZE(overlay_sysfs_attrs); ++i) {
  1538			error = device_create_file(info->dev, &overlay_sysfs_attrs[i]);
  1539			if (error)
  1540				break;
  1541		}
  1542	
  1543		if (error) {
> 1544			while (--i >= 0)
  1545				device_remove_file(info->dev, &overlay_sysfs_attrs[i]);
  1546			return error;
  1547		}
  1548	
  1549		return 0;
  1550	}
  1551
Arnd Bergmann Feb. 19, 2025, 6:47 a.m. UTC | #2
On Sat, Feb 8, 2025, at 10:29, oushixiong1025@163.com wrote:
> From: Shixiong Ou <oushixiong@kylinos.cn>
>
> 1. The device_remove_file() need to be called when driver is removing.
> 2. The device_remove_file() need to be called if the call to
>    device_create_file() fails.

This should probably use device_add_group() instead of
individual files to simplify both creation and removal.
It would also avoid the bug you introduced that gcc warns
about.

      Arnd
Shixiong Ou Feb. 19, 2025, 7:40 a.m. UTC | #3
在 2025/2/19 14:47, Arnd Bergmann 写道:
> On Sat, Feb 8, 2025, at 10:29, oushixiong1025@163.com wrote:
>> From: Shixiong Ou <oushixiong@kylinos.cn>
>>
>> 1. The device_remove_file() need to be called when driver is removing.
>> 2. The device_remove_file() need to be called if the call to
>>     device_create_file() fails.
> This should probably use device_add_group() instead of
> individual files to simplify both creation and removal.
> It would also avoid the bug you introduced that gcc warns
> about.
>
>        Arnd

Thank you for your suggestion. I will incorporate your advice and resend a patch.

Thanks and Regards,
Shixiong Ou.
diff mbox series

Patch

diff --git a/drivers/video/fbdev/sh_mobile_lcdcfb.c b/drivers/video/fbdev/sh_mobile_lcdcfb.c
index 4715dcb59811..c52661d5491a 100644
--- a/drivers/video/fbdev/sh_mobile_lcdcfb.c
+++ b/drivers/video/fbdev/sh_mobile_lcdcfb.c
@@ -1504,10 +1504,14 @@  static void
 sh_mobile_lcdc_overlay_fb_unregister(struct sh_mobile_lcdc_overlay *ovl)
 {
 	struct fb_info *info = ovl->info;
+	unsigned int i;
 
 	if (info == NULL || info->dev == NULL)
 		return;
 
+	for (i = 0; i < ARRAY_SIZE(overlay_sysfs_attrs); ++i)
+		device_remove_file(info->dev, &overlay_sysfs_attrs[i]);
+
 	unregister_framebuffer(ovl->info);
 }
 
@@ -1516,7 +1520,7 @@  sh_mobile_lcdc_overlay_fb_register(struct sh_mobile_lcdc_overlay *ovl)
 {
 	struct sh_mobile_lcdc_priv *lcdc = ovl->channel->lcdc;
 	struct fb_info *info = ovl->info;
-	unsigned int i;
+	unsigned int i, error = 0;
 	int ret;
 
 	if (info == NULL)
@@ -1531,9 +1535,15 @@  sh_mobile_lcdc_overlay_fb_register(struct sh_mobile_lcdc_overlay *ovl)
 		 info->var.yres, info->var.bits_per_pixel);
 
 	for (i = 0; i < ARRAY_SIZE(overlay_sysfs_attrs); ++i) {
-		ret = device_create_file(info->dev, &overlay_sysfs_attrs[i]);
-		if (ret < 0)
-			return ret;
+		error = device_create_file(info->dev, &overlay_sysfs_attrs[i]);
+		if (error)
+			break;
+	}
+
+	if (error) {
+		while (--i >= 0)
+			device_remove_file(info->dev, &overlay_sysfs_attrs[i]);
+		return error;
 	}
 
 	return 0;