* [PATCH] block: fix attribute_group lost if set before add_disk
@ 2022-06-10 7:16 Sun Feng
2022-06-10 8:13 ` Christoph Hellwig
0 siblings, 1 reply; 2+ messages in thread
From: Sun Feng @ 2022-06-10 7:16 UTC (permalink / raw)
To: axboe, linux-block, linux-kernel; +Cc: loyou85
after commit 52b85909f85d("block: fold register_disk into device_add_disk")
when set attribute_group with following code:
disk_to_dev(disk)->groups = attr_groups;
err = add_disk(disk);
disk_to_dev(disk)->groups will set to NULL in device_add_disk,
static inline int __must_check add_disk(struct gendisk *disk)
{
return device_add_disk(NULL, disk, NULL);
}
int __must_check device_add_disk(struct device *parent, ...
const struct attribute_group **groups)
{
…
ddev->groups = groups
and it will lose attribute group set.
Signed-off-by: Sun Feng <loyou85@gmail.com>
---
block/genhd.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/block/genhd.c b/block/genhd.c
index 27205ae..6b76f67 100644
--- a/block/genhd.c
+++ b/block/genhd.c
@@ -459,7 +459,10 @@ int __must_check device_add_disk(struct device *parent, struct gendisk *disk,
dev_set_uevent_suppress(ddev, 1);
ddev->parent = parent;
- ddev->groups = groups;
+ if (groups) {
+ WARN_ON(ddev->groups);
+ ddev->groups = groups;
+ }
dev_set_name(ddev, "%s", disk->disk_name);
if (!(disk->flags & GENHD_FL_HIDDEN))
ddev->devt = MKDEV(disk->major, disk->first_minor);
--
2.7.4
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] block: fix attribute_group lost if set before add_disk
2022-06-10 7:16 [PATCH] block: fix attribute_group lost if set before add_disk Sun Feng
@ 2022-06-10 8:13 ` Christoph Hellwig
0 siblings, 0 replies; 2+ messages in thread
From: Christoph Hellwig @ 2022-06-10 8:13 UTC (permalink / raw)
To: Sun Feng; +Cc: axboe, linux-block, linux-kernel
On Fri, Jun 10, 2022 at 03:16:29PM +0800, Sun Feng wrote:
> after commit 52b85909f85d("block: fold register_disk into device_add_disk")
> when set attribute_group with following code:
>
> disk_to_dev(disk)->groups = attr_groups;
> err = add_disk(disk);
>
> disk_to_dev(disk)->groups will set to NULL in device_add_disk,
>
> static inline int __must_check add_disk(struct gendisk *disk)
> {
> return device_add_disk(NULL, disk, NULL);
> }
> int __must_check device_add_disk(struct device *parent, ...
> const struct attribute_group **groups)
> {
> …
> ddev->groups = groups
>
> and it will lose attribute group set.
Well, your are not supposed to set the attribute group yourself, but
instead pass it to device_add_disk.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2022-06-10 8:13 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-10 7:16 [PATCH] block: fix attribute_group lost if set before add_disk Sun Feng
2022-06-10 8:13 ` Christoph Hellwig
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.