2022-02-26 01:38:39

by Dmitry Torokhov

[permalink] [raw]
Subject: [PATCH] HID: vivaldi: fix sysfs attributes leak

The driver creates the top row map sysfs attribute in input_configured()
method; unfortunately we do not have a callback that is executed when HID
interface is unbound, thus we are leaking these sysfs attributes, for
example when device is disconnected.

To fix it let's switch to managed version of adding sysfs attributes which
will ensure that they are destroyed when the driver is unbound.

Fixes: 14c9c014babe ("HID: add vivaldi HID driver")
Signed-off-by: Dmitry Torokhov <[email protected]>
---

Compiled only.

drivers/hid/hid-vivaldi.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/hid/hid-vivaldi.c b/drivers/hid/hid-vivaldi.c
index efa6140915f4..42ceb2058a09 100644
--- a/drivers/hid/hid-vivaldi.c
+++ b/drivers/hid/hid-vivaldi.c
@@ -144,7 +144,7 @@ static void vivaldi_feature_mapping(struct hid_device *hdev,
static int vivaldi_input_configured(struct hid_device *hdev,
struct hid_input *hidinput)
{
- return sysfs_create_group(&hdev->dev.kobj, &input_attribute_group);
+ return devm_device_add_group(&hdev->dev, &input_attribute_group);
}

static const struct hid_device_id vivaldi_table[] = {
--
2.35.1.574.g5d30c73bfb-goog


--
Dmitry


2022-02-26 06:18:16

by Dmitry Torokhov

[permalink] [raw]
Subject: Re: [PATCH] HID: vivaldi: fix sysfs attributes leak

On Fri, Feb 25, 2022 at 08:55:26PM -0800, Stephen Boyd wrote:
> Quoting Dmitry Torokhov (2022-02-25 17:18:58)
> > The driver creates the top row map sysfs attribute in input_configured()
> > method; unfortunately we do not have a callback that is executed when HID
> > interface is unbound, thus we are leaking these sysfs attributes, for
> > example when device is disconnected.
> >
> > To fix it let's switch to managed version of adding sysfs attributes which
> > will ensure that they are destroyed when the driver is unbound.
> >
> > Fixes: 14c9c014babe ("HID: add vivaldi HID driver")
> > Signed-off-by: Dmitry Torokhov <[email protected]>
> > ---
>
> Makes sense
>
> Tested-by: Stephen Boyd <[email protected]>
> Reviewed-by: Stephen Boyd <[email protected]>
>
> will you make a similar change for the hid-google-hammer driver?

Yeah, I was taking a closer look at your series and that was the result
of it.

Thanks.

--
Dmitry

2022-02-26 06:19:42

by Stephen Boyd

[permalink] [raw]
Subject: Re: [PATCH] HID: vivaldi: fix sysfs attributes leak

Quoting Dmitry Torokhov (2022-02-25 17:18:58)
> The driver creates the top row map sysfs attribute in input_configured()
> method; unfortunately we do not have a callback that is executed when HID
> interface is unbound, thus we are leaking these sysfs attributes, for
> example when device is disconnected.
>
> To fix it let's switch to managed version of adding sysfs attributes which
> will ensure that they are destroyed when the driver is unbound.
>
> Fixes: 14c9c014babe ("HID: add vivaldi HID driver")
> Signed-off-by: Dmitry Torokhov <[email protected]>
> ---

Makes sense

Tested-by: Stephen Boyd <[email protected]>
Reviewed-by: Stephen Boyd <[email protected]>

will you make a similar change for the hid-google-hammer driver?

2022-03-02 19:57:44

by Jiri Kosina

[permalink] [raw]
Subject: Re: [PATCH] HID: vivaldi: fix sysfs attributes leak

On Fri, 25 Feb 2022, Dmitry Torokhov wrote:

> The driver creates the top row map sysfs attribute in input_configured()
> method; unfortunately we do not have a callback that is executed when HID
> interface is unbound, thus we are leaking these sysfs attributes, for
> example when device is disconnected.
>
> To fix it let's switch to managed version of adding sysfs attributes which
> will ensure that they are destroyed when the driver is unbound.
>
> Fixes: 14c9c014babe ("HID: add vivaldi HID driver")
> Signed-off-by: Dmitry Torokhov <[email protected]>
> ---
>
> Compiled only.
>
> drivers/hid/hid-vivaldi.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/hid/hid-vivaldi.c b/drivers/hid/hid-vivaldi.c
> index efa6140915f4..42ceb2058a09 100644
> --- a/drivers/hid/hid-vivaldi.c
> +++ b/drivers/hid/hid-vivaldi.c
> @@ -144,7 +144,7 @@ static void vivaldi_feature_mapping(struct hid_device *hdev,
> static int vivaldi_input_configured(struct hid_device *hdev,
> struct hid_input *hidinput)
> {
> - return sysfs_create_group(&hdev->dev.kobj, &input_attribute_group);
> + return devm_device_add_group(&hdev->dev, &input_attribute_group);
> }
>
> static const struct hid_device_id vivaldi_table[] = {

Applied, thanks Dmitry.

--
Jiri Kosina
SUSE Labs

2022-03-09 00:52:59

by Dmitry Torokhov

[permalink] [raw]
Subject: Re: [PATCH] HID: vivaldi: fix sysfs attributes leak

On Tue, Mar 1, 2022 at 6:31 AM Jiri Kosina <[email protected]> wrote:
>
> On Fri, 25 Feb 2022, Dmitry Torokhov wrote:
>
> > The driver creates the top row map sysfs attribute in input_configured()
> > method; unfortunately we do not have a callback that is executed when HID
> > interface is unbound, thus we are leaking these sysfs attributes, for
> > example when device is disconnected.
> >
> > To fix it let's switch to managed version of adding sysfs attributes which
> > will ensure that they are destroyed when the driver is unbound.
> >
> > Fixes: 14c9c014babe ("HID: add vivaldi HID driver")
> > Signed-off-by: Dmitry Torokhov <[email protected]>
> > ---
> >
> > Compiled only.
> >
> > drivers/hid/hid-vivaldi.c | 2 +-
> > 1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/drivers/hid/hid-vivaldi.c b/drivers/hid/hid-vivaldi.c
> > index efa6140915f4..42ceb2058a09 100644
> > --- a/drivers/hid/hid-vivaldi.c
> > +++ b/drivers/hid/hid-vivaldi.c
> > @@ -144,7 +144,7 @@ static void vivaldi_feature_mapping(struct hid_device *hdev,
> > static int vivaldi_input_configured(struct hid_device *hdev,
> > struct hid_input *hidinput)
> > {
> > - return sysfs_create_group(&hdev->dev.kobj, &input_attribute_group);
> > + return devm_device_add_group(&hdev->dev, &input_attribute_group);
> > }
> >
> > static const struct hid_device_id vivaldi_table[] = {
>
> Applied, thanks Dmitry.

Jiri, are you planning to send this for 5.17 or 5.18?

Thanks.

--
Dmitry

2022-03-09 12:14:55

by Jiri Kosina

[permalink] [raw]
Subject: Re: [PATCH] HID: vivaldi: fix sysfs attributes leak

On Tue, 8 Mar 2022, Dmitry Torokhov wrote:

> Jiri, are you planning to send this for 5.17 or 5.18?

Hi Dmitry,

I've sent it to Linus for 5.17-rc still earlier today.

--
Jiri Kosina
SUSE Labs