diff mbox series

HID: potential dereference of null pointer

Message ID 20211215083605.117638-1-jiasheng@iscas.ac.cn
State Accepted
Commit 13251ce1dd9bb525da2becb9b26fdfb94ca58659
Headers show
Series HID: potential dereference of null pointer | expand

Commit Message

Jiasheng Jiang Dec. 15, 2021, 8:36 a.m. UTC
The return value of devm_kzalloc() needs to be checked.
To avoid hdev->dev->driver_data to be null in case of the failure of
alloc.

Fixes: 14c9c014babe ("HID: add vivaldi HID driver")
Signed-off-by: Jiasheng Jiang <jiasheng@iscas.ac.cn>
---
 drivers/hid/hid-vivaldi.c | 3 +++
 1 file changed, 3 insertions(+)

Comments

Benjamin Tissoires Dec. 20, 2021, 2:10 p.m. UTC | #1
On Wed, Dec 15, 2021 at 9:36 AM Jiasheng Jiang <jiasheng@iscas.ac.cn> wrote:
>
> The return value of devm_kzalloc() needs to be checked.
> To avoid hdev->dev->driver_data to be null in case of the failure of
> alloc.
>
> Fixes: 14c9c014babe ("HID: add vivaldi HID driver")
> Signed-off-by: Jiasheng Jiang <jiasheng@iscas.ac.cn>
> ---

Thanks for the fix. I have now pushed it to hid.git, branch
for-5.16/upstream-fixes

Cheers,
Benjamin

>  drivers/hid/hid-vivaldi.c | 3 +++
>  1 file changed, 3 insertions(+)
>
> diff --git a/drivers/hid/hid-vivaldi.c b/drivers/hid/hid-vivaldi.c
> index cd7ada48b1d9..72957a9f7117 100644
> --- a/drivers/hid/hid-vivaldi.c
> +++ b/drivers/hid/hid-vivaldi.c
> @@ -57,6 +57,9 @@ static int vivaldi_probe(struct hid_device *hdev,
>         int ret;
>
>         drvdata = devm_kzalloc(&hdev->dev, sizeof(*drvdata), GFP_KERNEL);
> +       if (!drvdata)
> +               return -ENOMEM;
> +
>         hid_set_drvdata(hdev, drvdata);
>
>         ret = hid_parse(hdev);
> --
> 2.25.1
>
diff mbox series

Patch

diff --git a/drivers/hid/hid-vivaldi.c b/drivers/hid/hid-vivaldi.c
index cd7ada48b1d9..72957a9f7117 100644
--- a/drivers/hid/hid-vivaldi.c
+++ b/drivers/hid/hid-vivaldi.c
@@ -57,6 +57,9 @@  static int vivaldi_probe(struct hid_device *hdev,
 	int ret;
 
 	drvdata = devm_kzalloc(&hdev->dev, sizeof(*drvdata), GFP_KERNEL);
+	if (!drvdata)
+		return -ENOMEM;
+
 	hid_set_drvdata(hdev, drvdata);
 
 	ret = hid_parse(hdev);