The Linux Kernel Mailing List
 help / color / mirror / Atom feed
* [PATCH v2] fbdev: lcdcfb: add missing device_remove_file()
@ 2025-02-08  9:29 oushixiong1025
  2025-02-19  5:25 ` kernel test robot
  2025-02-19  6:47 ` Arnd Bergmann
  0 siblings, 2 replies; 4+ messages in thread
From: oushixiong1025 @ 2025-02-08  9:29 UTC (permalink / raw)
  To: Helge Deller
  Cc: Thomas Zimmermann, Laurent Pinchart, Lee Jones,
	Uwe Kleine-König, Arnd Bergmann, linux-fbdev, dri-devel,
	linux-kernel, Shixiong Ou

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(-)

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;
-- 
2.17.1


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

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

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-02-08  9:29 [PATCH v2] fbdev: lcdcfb: add missing device_remove_file() oushixiong1025
2025-02-19  5:25 ` kernel test robot
2025-02-19  6:47 ` Arnd Bergmann
2025-02-19  7:40   ` Shixiong Ou

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