diff mbox series

[3/3] block: warn if ->groups is set when calling add_disk

Message ID 20210920072726.1159572-4-hch@lst.de (mailing list archive)
State Superseded
Headers show
Series [1/3] nvdimm/pmem: fix creating the dax group | expand

Commit Message

Christoph Hellwig Sept. 20, 2021, 7:27 a.m. UTC
The proper API is to pass the groups to device_add_disk, but the code
used to also allow groups being set before calling *add_disk.  Warn
about that but keep the group pointer intact for now so that it can
be removed again after a grace period.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Fixes: 52b85909f85d ("block: fold register_disk into device_add_disk")
---
 block/genhd.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

Comments

Ira Weiny Sept. 20, 2021, 10:52 p.m. UTC | #1
On Mon, Sep 20, 2021 at 09:27:26AM +0200, Christoph Hellwig wrote:
> The proper API is to pass the groups to device_add_disk, but the code
> used to also allow groups being set before calling *add_disk.  Warn
> about that but keep the group pointer intact for now so that it can
> be removed again after a grace period.
> 
> Signed-off-by: Christoph Hellwig <hch@lst.de>
> Fixes: 52b85909f85d ("block: fold register_disk into device_add_disk")

Reviewed-by: Ira Weiny <ira.weiny@intel.com>

> ---
>  block/genhd.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/block/genhd.c b/block/genhd.c
> index 7b6e5e1cf9564..409cf608cc5bd 100644
> --- a/block/genhd.c
> +++ b/block/genhd.c
> @@ -439,7 +439,8 @@ int device_add_disk(struct device *parent, struct gendisk *disk,
>  	dev_set_uevent_suppress(ddev, 1);
>  
>  	ddev->parent = parent;
> -	ddev->groups = groups;
> +	if (!WARN_ON_ONCE(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.30.2
>
Dan Williams Sept. 20, 2021, 11:50 p.m. UTC | #2
On Mon, Sep 20, 2021 at 12:30 AM Christoph Hellwig <hch@lst.de> wrote:
>
> The proper API is to pass the groups to device_add_disk, but the code
> used to also allow groups being set before calling *add_disk.  Warn
> about that but keep the group pointer intact for now so that it can
> be removed again after a grace period.
>
> Signed-off-by: Christoph Hellwig <hch@lst.de>
> Fixes: 52b85909f85d ("block: fold register_disk into device_add_disk")
> ---
>  block/genhd.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/block/genhd.c b/block/genhd.c
> index 7b6e5e1cf9564..409cf608cc5bd 100644
> --- a/block/genhd.c
> +++ b/block/genhd.c
> @@ -439,7 +439,8 @@ int device_add_disk(struct device *parent, struct gendisk *disk,
>         dev_set_uevent_suppress(ddev, 1);
>
>         ddev->parent = parent;
> -       ddev->groups = groups;
> +       if (!WARN_ON_ONCE(ddev->groups))
> +               ddev->groups = groups;

That feels too compact to me, and dev_WARN_ONCE() might save someone a
git blame to look up the reason for the warning:

    dev_WARN_ONCE(parent, ddev->groups, "unexpected pre-populated
attribute group\n");
    if (!ddev->groups)
        ddev->groups = groups;

...but not a deal breaker. Either way you can add:

Reviewed-by: Dan Williams <dan.j.williams@intel.com>

Jens, I'm ok for the final spin of this series to go through block.git
since the referenced commits in Fixes: went that route, just let me
know if you want me to take them.
Christoph Hellwig Sept. 21, 2021, 6:32 a.m. UTC | #3
On Mon, Sep 20, 2021 at 04:50:03PM -0700, Dan Williams wrote:
> >
> >         ddev->parent = parent;
> > -       ddev->groups = groups;
> > +       if (!WARN_ON_ONCE(ddev->groups))
> > +               ddev->groups = groups;
> 
> That feels too compact to me, and dev_WARN_ONCE() might save someone a
> git blame to look up the reason for the warning:
> 
>     dev_WARN_ONCE(parent, ddev->groups, "unexpected pre-populated
> attribute group\n");
>     if (!ddev->groups)
>         ddev->groups = groups;
> 
> ...but not a deal breaker. Either way you can add:
> 

I'd rather keep it simple and optmize for the normal case..
diff mbox series

Patch

diff --git a/block/genhd.c b/block/genhd.c
index 7b6e5e1cf9564..409cf608cc5bd 100644
--- a/block/genhd.c
+++ b/block/genhd.c
@@ -439,7 +439,8 @@  int device_add_disk(struct device *parent, struct gendisk *disk,
 	dev_set_uevent_suppress(ddev, 1);
 
 	ddev->parent = parent;
-	ddev->groups = groups;
+	if (!WARN_ON_ONCE(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);