Linux Framebuffer Layer development
 help / color / mirror / Atom feed
From: Helge Deller <deller@gmx.de>
To: Hans de Goede <johannes.goede@oss.qualcomm.com>,
	Simona Vetter <simona@ffwll.ch>
Cc: Thomas Zimmermann <tzimmermann@suse.de>,
	dri-devel@lists.freedesktop.org, linux-fbdev@vger.kernel.org,
	stable@vger.kernel.org, Shixiong Ou <oushixiong@kylinos.cn>
Subject: Re: [PATCH] fbdev: Use device_create_with_groups() to fix sysfs groups registration race
Date: Tue, 30 Dec 2025 09:56:20 +0100	[thread overview]
Message-ID: <6443ccc9-d6cd-45d5-9d6d-ee4589a8aa0f@gmx.de> (raw)
In-Reply-To: <20251221165740.15821-1-johannes.goede@oss.qualcomm.com>

On 12/21/25 17:57, Hans de Goede wrote:
> The fbdev sysfs attributes are registered after sending the uevent for
> the device creation, leaving a race window where e.g. udev rules may
> not be able to access the sysfs attributes because the registration is
> not done yet.
> 
> Fix this by switching to device_create_with_groups(). This also results in
> a nice cleanup. After switching to device_create_with_groups() all that
> is left of fb_init_device() is setting the drvdata and that can be passed
> to device_create[_with_groups]() too. After which fb_init_device() can
> be completely removed.
> 
> Dropping fb_init_device() + fb_cleanup_device() in turn allows removing
> fb_info.class_flag as they were the only user of this field.
> 
> Fixes: 5fc830d6aca1 ("fbdev: Register sysfs groups through device_add_group")
> Cc: stable@vger.kernel.org
> Cc: Shixiong Ou <oushixiong@kylinos.cn>
> Signed-off-by: Hans de Goede <johannes.goede@oss.qualcomm.com>

applied to fbdev git tree.

Thanks!
Helge


> ---
> Note the fixes tag is technically wrong. This race has existed forever.
> The commit I picked for the fixes tag is a dependency of this change not
> the commit introducing the race. I don't believe that backporting this
> back any further is useful which is why I went with this commit.
> ---
>   drivers/video/fbdev/core/fbsysfs.c | 36 +++---------------------------
>   include/linux/fb.h                 |  1 -
>   2 files changed, 3 insertions(+), 34 deletions(-)
> 
> diff --git a/drivers/video/fbdev/core/fbsysfs.c b/drivers/video/fbdev/core/fbsysfs.c
> index b8344c40073b..baa2bae0fb5b 100644
> --- a/drivers/video/fbdev/core/fbsysfs.c
> +++ b/drivers/video/fbdev/core/fbsysfs.c
> @@ -12,8 +12,6 @@
>   
>   #include "fb_internal.h"
>   
> -#define FB_SYSFS_FLAG_ATTR 1
> -
>   static int activate(struct fb_info *fb_info, struct fb_var_screeninfo *var)
>   {
>   	int err;
> @@ -451,33 +449,7 @@ static struct attribute *fb_device_attrs[] = {
>   	NULL,
>   };
>   
> -static const struct attribute_group fb_device_attr_group = {
> -	.attrs          = fb_device_attrs,
> -};
> -
> -static int fb_init_device(struct fb_info *fb_info)
> -{
> -	int ret;
> -
> -	dev_set_drvdata(fb_info->dev, fb_info);
> -
> -	fb_info->class_flag |= FB_SYSFS_FLAG_ATTR;
> -
> -	ret = device_add_group(fb_info->dev, &fb_device_attr_group);
> -	if (ret)
> -		fb_info->class_flag &= ~FB_SYSFS_FLAG_ATTR;
> -
> -	return 0;
> -}
> -
> -static void fb_cleanup_device(struct fb_info *fb_info)
> -{
> -	if (fb_info->class_flag & FB_SYSFS_FLAG_ATTR) {
> -		device_remove_group(fb_info->dev, &fb_device_attr_group);
> -
> -		fb_info->class_flag &= ~FB_SYSFS_FLAG_ATTR;
> -	}
> -}
> +ATTRIBUTE_GROUPS(fb_device);
>   
>   int fb_device_create(struct fb_info *fb_info)
>   {
> @@ -485,14 +457,13 @@ int fb_device_create(struct fb_info *fb_info)
>   	dev_t devt = MKDEV(FB_MAJOR, node);
>   	int ret;
>   
> -	fb_info->dev = device_create(fb_class, fb_info->device, devt, NULL, "fb%d", node);
> +	fb_info->dev = device_create_with_groups(fb_class, fb_info->device, devt, fb_info,
> +						 fb_device_groups, "fb%d", node);
>   	if (IS_ERR(fb_info->dev)) {
>   		/* Not fatal */
>   		ret = PTR_ERR(fb_info->dev);
>   		pr_warn("Unable to create device for framebuffer %d; error %d\n", node, ret);
>   		fb_info->dev = NULL;
> -	} else {
> -		fb_init_device(fb_info);
>   	}
>   
>   	return 0;
> @@ -505,7 +476,6 @@ void fb_device_destroy(struct fb_info *fb_info)
>   	if (!fb_info->dev)
>   		return;
>   
> -	fb_cleanup_device(fb_info);
>   	device_destroy(fb_class, devt);
>   	fb_info->dev = NULL;
>   }
> diff --git a/include/linux/fb.h b/include/linux/fb.h
> index 05cc251035da..c3302d513546 100644
> --- a/include/linux/fb.h
> +++ b/include/linux/fb.h
> @@ -497,7 +497,6 @@ struct fb_info {
>   #if defined(CONFIG_FB_DEVICE)
>   	struct device *dev;		/* This is this fb device */
>   #endif
> -	int class_flag;                    /* private sysfs flags */
>   #ifdef CONFIG_FB_TILEBLITTING
>   	struct fb_tile_ops *tileops;    /* Tile Blitting */
>   #endif


      reply	other threads:[~2025-12-30  8:56 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-12-21 16:57 [PATCH] fbdev: Use device_create_with_groups() to fix sysfs groups registration race Hans de Goede
2025-12-30  8:56 ` Helge Deller [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=6443ccc9-d6cd-45d5-9d6d-ee4589a8aa0f@gmx.de \
    --to=deller@gmx.de \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=johannes.goede@oss.qualcomm.com \
    --cc=linux-fbdev@vger.kernel.org \
    --cc=oushixiong@kylinos.cn \
    --cc=simona@ffwll.ch \
    --cc=stable@vger.kernel.org \
    --cc=tzimmermann@suse.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox