2018-06-11 08:56:37

by Zhouyang Jia

[permalink] [raw]
Subject: [PATCH] HID: hid-ntrig: add error handling for sysfs_create_group

When sysfs_create_group fails, the lack of error-handling code may
cause unexpected results.

This patch adds error-handling code after calling sysfs_create_group.

Signed-off-by: Zhouyang Jia <[email protected]>
---
drivers/hid/hid-ntrig.c | 4 ++++
1 file changed, 4 insertions(+)

diff --git a/drivers/hid/hid-ntrig.c b/drivers/hid/hid-ntrig.c
index 43b1c72..1e70dae 100644
--- a/drivers/hid/hid-ntrig.c
+++ b/drivers/hid/hid-ntrig.c
@@ -955,6 +955,10 @@ static int ntrig_probe(struct hid_device *hdev, const struct hid_device_id *id)

ret = sysfs_create_group(&hdev->dev.kobj,
&ntrig_attribute_group);
+ if (ret) {
+ hid_err(hdev, "cannot create sysfs group\n");
+ goto err_free;
+ }

return 0;
err_free:
--
2.7.4



2018-06-11 12:21:22

by Jiri Kosina

[permalink] [raw]
Subject: Re: [PATCH] HID: hid-ntrig: add error handling for sysfs_create_group

On Mon, 11 Jun 2018, Zhouyang Jia wrote:

> When sysfs_create_group fails, the lack of error-handling code may
> cause unexpected results.
>
> This patch adds error-handling code after calling sysfs_create_group.
>
> Signed-off-by: Zhouyang Jia <[email protected]>
> ---
> drivers/hid/hid-ntrig.c | 4 ++++
> 1 file changed, 4 insertions(+)
>
> diff --git a/drivers/hid/hid-ntrig.c b/drivers/hid/hid-ntrig.c
> index 43b1c72..1e70dae 100644
> --- a/drivers/hid/hid-ntrig.c
> +++ b/drivers/hid/hid-ntrig.c
> @@ -955,6 +955,10 @@ static int ntrig_probe(struct hid_device *hdev, const struct hid_device_id *id)
>
> ret = sysfs_create_group(&hdev->dev.kobj,
> &ntrig_attribute_group);
> + if (ret) {
> + hid_err(hdev, "cannot create sysfs group\n");
> + goto err_free;
> + }

Is it really necessarily to bail out completely here and render the device
dysfunctional? Issuing a warning about sysfs knobs being unavailable might
be more appropriate.

Thanks,

--
Jiri Kosina
SUSE Labs


2018-06-14 13:39:03

by Zhouyang Jia

[permalink] [raw]
Subject: [PATCH v2] HID: hid-ntrig: add error handling for sysfs_create_group

When sysfs_create_group fails, the lack of error-handling code may
cause unexpected results.

This patch adds error-handling code after calling sysfs_create_group.

Signed-off-by: Zhouyang Jia <[email protected]>
---
v1->v2:
- Remove goto statement.
---
drivers/hid/hid-ntrig.c | 2 ++
1 file changed, 2 insertions(+)

diff --git a/drivers/hid/hid-ntrig.c b/drivers/hid/hid-ntrig.c
index 43b1c72..9bc6f48 100644
--- a/drivers/hid/hid-ntrig.c
+++ b/drivers/hid/hid-ntrig.c
@@ -955,6 +955,8 @@ static int ntrig_probe(struct hid_device *hdev, const struct hid_device_id *id)

ret = sysfs_create_group(&hdev->dev.kobj,
&ntrig_attribute_group);
+ if (ret)
+ hid_err(hdev, "cannot create sysfs group\n");

return 0;
err_free:
--
2.7.4


2018-06-25 13:18:05

by Jiri Kosina

[permalink] [raw]
Subject: Re: [PATCH v2] HID: hid-ntrig: add error handling for sysfs_create_group

On Thu, 14 Jun 2018, Zhouyang Jia wrote:

> When sysfs_create_group fails, the lack of error-handling code may
> cause unexpected results.
>
> This patch adds error-handling code after calling sysfs_create_group.
>
> Signed-off-by: Zhouyang Jia <[email protected]>
> ---
> v1->v2:
> - Remove goto statement.

Applied, thanks.

--
Jiri Kosina
SUSE Labs