diff mbox series

USB: usbip: convert platform driver to use dev_groups

Message ID 20190805193636.25560-5-gregkh@linuxfoundation.org (mailing list archive)
State Mainlined
Commit 91148dbad80bb6024389287be4aefcbf20b2d0e4
Headers show
Series USB: usbip: convert platform driver to use dev_groups | expand

Commit Message

Greg Kroah-Hartman Aug. 5, 2019, 7:36 p.m. UTC
Platform drivers now have the option to have the platform core create
and remove any needed sysfs attribute files.  So take advantage of that
and do not register "by hand" any sysfs files.

Cc: Valentina Manea <valentina.manea.m@gmail.com>
Cc: Shuah Khan <shuah@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
 drivers/usb/usbip/vudc.h       | 2 +-
 drivers/usb/usbip/vudc_dev.c   | 9 ---------
 drivers/usb/usbip/vudc_main.c  | 1 +
 drivers/usb/usbip/vudc_sysfs.c | 7 ++++++-
 4 files changed, 8 insertions(+), 11 deletions(-)

Comments

Shuah Aug. 5, 2019, 8:22 p.m. UTC | #1
On 8/5/19 1:36 PM, Greg Kroah-Hartman wrote:
> Platform drivers now have the option to have the platform core create
> and remove any needed sysfs attribute files.  So take advantage of that
> and do not register "by hand" any sysfs files.
> 
> Cc: Valentina Manea <valentina.manea.m@gmail.com>
> Cc: Shuah Khan <shuah@kernel.org>
> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> ---
>   drivers/usb/usbip/vudc.h       | 2 +-
>   drivers/usb/usbip/vudc_dev.c   | 9 ---------
>   drivers/usb/usbip/vudc_main.c  | 1 +
>   drivers/usb/usbip/vudc_sysfs.c | 7 ++++++-
>   4 files changed, 8 insertions(+), 11 deletions(-)
> 
> diff --git a/drivers/usb/usbip/vudc.h b/drivers/usb/usbip/vudc.h
> index cf968192e59f..1bd4bc005829 100644
> --- a/drivers/usb/usbip/vudc.h
> +++ b/drivers/usb/usbip/vudc.h
> @@ -115,7 +115,7 @@ struct vudc_device {
>   	struct list_head dev_entry;
>   };
>   
> -extern const struct attribute_group vudc_attr_group;
> +extern const struct attribute_group *vudc_groups[];
>   
>   /* visible everywhere */
>   
> diff --git a/drivers/usb/usbip/vudc_dev.c b/drivers/usb/usbip/vudc_dev.c
> index a72c17ff1c6a..c8eeabdd9b56 100644
> --- a/drivers/usb/usbip/vudc_dev.c
> +++ b/drivers/usb/usbip/vudc_dev.c
> @@ -616,18 +616,10 @@ int vudc_probe(struct platform_device *pdev)
>   	if (ret < 0)
>   		goto err_add_udc;
>   
> -	ret = sysfs_create_group(&pdev->dev.kobj, &vudc_attr_group);
> -	if (ret) {
> -		dev_err(&udc->pdev->dev, "create sysfs files\n");
> -		goto err_sysfs;
> -	}
> -
>   	platform_set_drvdata(pdev, udc);
>   
>   	return ret;
>   
> -err_sysfs:
> -	usb_del_gadget_udc(&udc->gadget);
>   err_add_udc:
>   	cleanup_vudc_hw(udc);
>   err_init_vudc_hw:
> @@ -640,7 +632,6 @@ int vudc_remove(struct platform_device *pdev)
>   {
>   	struct vudc *udc = platform_get_drvdata(pdev);
>   
> -	sysfs_remove_group(&pdev->dev.kobj, &vudc_attr_group);
>   	usb_del_gadget_udc(&udc->gadget);
>   	cleanup_vudc_hw(udc);
>   	kfree(udc);
> diff --git a/drivers/usb/usbip/vudc_main.c b/drivers/usb/usbip/vudc_main.c
> index 390733e6937e..678faa82598c 100644
> --- a/drivers/usb/usbip/vudc_main.c
> +++ b/drivers/usb/usbip/vudc_main.c
> @@ -22,6 +22,7 @@ static struct platform_driver vudc_driver = {
>   	.remove		= vudc_remove,
>   	.driver		= {
>   		.name	= GADGET_NAME,
> +		.dev_groups = vudc_groups,
>   	},
>   };
>   
> diff --git a/drivers/usb/usbip/vudc_sysfs.c b/drivers/usb/usbip/vudc_sysfs.c
> index 6dcd3ff655c3..100f680c572a 100644
> --- a/drivers/usb/usbip/vudc_sysfs.c
> +++ b/drivers/usb/usbip/vudc_sysfs.c
> @@ -215,7 +215,12 @@ static struct bin_attribute *dev_bin_attrs[] = {
>   	NULL,
>   };
>   
> -const struct attribute_group vudc_attr_group = {
> +static const struct attribute_group vudc_attr_group = {
>   	.attrs = dev_attrs,
>   	.bin_attrs = dev_bin_attrs,
>   };
> +
> +const struct attribute_group *vudc_groups[] = {
> +	&vudc_attr_group,
> +	NULL,
> +};
> 

Looks good to me.

Acked-by: Shuah Khan <skhan@linuxfoundation.org>

thanks,
-- Shuah
Greg Kroah-Hartman Aug. 6, 2019, 7:37 a.m. UTC | #2
On Mon, Aug 05, 2019 at 02:22:18PM -0600, shuah wrote:
> On 8/5/19 1:36 PM, Greg Kroah-Hartman wrote:
> > Platform drivers now have the option to have the platform core create
> > and remove any needed sysfs attribute files.  So take advantage of that
> > and do not register "by hand" any sysfs files.
> > 
> > Cc: Valentina Manea <valentina.manea.m@gmail.com>
> > Cc: Shuah Khan <shuah@kernel.org>
> > Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> > ---
> >   drivers/usb/usbip/vudc.h       | 2 +-
> >   drivers/usb/usbip/vudc_dev.c   | 9 ---------
> >   drivers/usb/usbip/vudc_main.c  | 1 +
> >   drivers/usb/usbip/vudc_sysfs.c | 7 ++++++-
> >   4 files changed, 8 insertions(+), 11 deletions(-)
> > 
> > diff --git a/drivers/usb/usbip/vudc.h b/drivers/usb/usbip/vudc.h
> > index cf968192e59f..1bd4bc005829 100644
> > --- a/drivers/usb/usbip/vudc.h
> > +++ b/drivers/usb/usbip/vudc.h
> > @@ -115,7 +115,7 @@ struct vudc_device {
> >   	struct list_head dev_entry;
> >   };
> > -extern const struct attribute_group vudc_attr_group;
> > +extern const struct attribute_group *vudc_groups[];
> >   /* visible everywhere */
> > diff --git a/drivers/usb/usbip/vudc_dev.c b/drivers/usb/usbip/vudc_dev.c
> > index a72c17ff1c6a..c8eeabdd9b56 100644
> > --- a/drivers/usb/usbip/vudc_dev.c
> > +++ b/drivers/usb/usbip/vudc_dev.c
> > @@ -616,18 +616,10 @@ int vudc_probe(struct platform_device *pdev)
> >   	if (ret < 0)
> >   		goto err_add_udc;
> > -	ret = sysfs_create_group(&pdev->dev.kobj, &vudc_attr_group);
> > -	if (ret) {
> > -		dev_err(&udc->pdev->dev, "create sysfs files\n");
> > -		goto err_sysfs;
> > -	}
> > -
> >   	platform_set_drvdata(pdev, udc);
> >   	return ret;
> > -err_sysfs:
> > -	usb_del_gadget_udc(&udc->gadget);
> >   err_add_udc:
> >   	cleanup_vudc_hw(udc);
> >   err_init_vudc_hw:
> > @@ -640,7 +632,6 @@ int vudc_remove(struct platform_device *pdev)
> >   {
> >   	struct vudc *udc = platform_get_drvdata(pdev);
> > -	sysfs_remove_group(&pdev->dev.kobj, &vudc_attr_group);
> >   	usb_del_gadget_udc(&udc->gadget);
> >   	cleanup_vudc_hw(udc);
> >   	kfree(udc);
> > diff --git a/drivers/usb/usbip/vudc_main.c b/drivers/usb/usbip/vudc_main.c
> > index 390733e6937e..678faa82598c 100644
> > --- a/drivers/usb/usbip/vudc_main.c
> > +++ b/drivers/usb/usbip/vudc_main.c
> > @@ -22,6 +22,7 @@ static struct platform_driver vudc_driver = {
> >   	.remove		= vudc_remove,
> >   	.driver		= {
> >   		.name	= GADGET_NAME,
> > +		.dev_groups = vudc_groups,
> >   	},
> >   };
> > diff --git a/drivers/usb/usbip/vudc_sysfs.c b/drivers/usb/usbip/vudc_sysfs.c
> > index 6dcd3ff655c3..100f680c572a 100644
> > --- a/drivers/usb/usbip/vudc_sysfs.c
> > +++ b/drivers/usb/usbip/vudc_sysfs.c
> > @@ -215,7 +215,12 @@ static struct bin_attribute *dev_bin_attrs[] = {
> >   	NULL,
> >   };
> > -const struct attribute_group vudc_attr_group = {
> > +static const struct attribute_group vudc_attr_group = {
> >   	.attrs = dev_attrs,
> >   	.bin_attrs = dev_bin_attrs,
> >   };
> > +
> > +const struct attribute_group *vudc_groups[] = {
> > +	&vudc_attr_group,
> > +	NULL,
> > +};
> > 
> 
> Looks good to me.
> 
> Acked-by: Shuah Khan <skhan@linuxfoundation.org>

Thanks for the review!

greg k-h
diff mbox series

Patch

diff --git a/drivers/usb/usbip/vudc.h b/drivers/usb/usbip/vudc.h
index cf968192e59f..1bd4bc005829 100644
--- a/drivers/usb/usbip/vudc.h
+++ b/drivers/usb/usbip/vudc.h
@@ -115,7 +115,7 @@  struct vudc_device {
 	struct list_head dev_entry;
 };
 
-extern const struct attribute_group vudc_attr_group;
+extern const struct attribute_group *vudc_groups[];
 
 /* visible everywhere */
 
diff --git a/drivers/usb/usbip/vudc_dev.c b/drivers/usb/usbip/vudc_dev.c
index a72c17ff1c6a..c8eeabdd9b56 100644
--- a/drivers/usb/usbip/vudc_dev.c
+++ b/drivers/usb/usbip/vudc_dev.c
@@ -616,18 +616,10 @@  int vudc_probe(struct platform_device *pdev)
 	if (ret < 0)
 		goto err_add_udc;
 
-	ret = sysfs_create_group(&pdev->dev.kobj, &vudc_attr_group);
-	if (ret) {
-		dev_err(&udc->pdev->dev, "create sysfs files\n");
-		goto err_sysfs;
-	}
-
 	platform_set_drvdata(pdev, udc);
 
 	return ret;
 
-err_sysfs:
-	usb_del_gadget_udc(&udc->gadget);
 err_add_udc:
 	cleanup_vudc_hw(udc);
 err_init_vudc_hw:
@@ -640,7 +632,6 @@  int vudc_remove(struct platform_device *pdev)
 {
 	struct vudc *udc = platform_get_drvdata(pdev);
 
-	sysfs_remove_group(&pdev->dev.kobj, &vudc_attr_group);
 	usb_del_gadget_udc(&udc->gadget);
 	cleanup_vudc_hw(udc);
 	kfree(udc);
diff --git a/drivers/usb/usbip/vudc_main.c b/drivers/usb/usbip/vudc_main.c
index 390733e6937e..678faa82598c 100644
--- a/drivers/usb/usbip/vudc_main.c
+++ b/drivers/usb/usbip/vudc_main.c
@@ -22,6 +22,7 @@  static struct platform_driver vudc_driver = {
 	.remove		= vudc_remove,
 	.driver		= {
 		.name	= GADGET_NAME,
+		.dev_groups = vudc_groups,
 	},
 };
 
diff --git a/drivers/usb/usbip/vudc_sysfs.c b/drivers/usb/usbip/vudc_sysfs.c
index 6dcd3ff655c3..100f680c572a 100644
--- a/drivers/usb/usbip/vudc_sysfs.c
+++ b/drivers/usb/usbip/vudc_sysfs.c
@@ -215,7 +215,12 @@  static struct bin_attribute *dev_bin_attrs[] = {
 	NULL,
 };
 
-const struct attribute_group vudc_attr_group = {
+static const struct attribute_group vudc_attr_group = {
 	.attrs = dev_attrs,
 	.bin_attrs = dev_bin_attrs,
 };
+
+const struct attribute_group *vudc_groups[] = {
+	&vudc_attr_group,
+	NULL,
+};