2008-12-20 18:26:16

by Adrian McMenamin

[permalink] [raw]
Subject: [PATCH] sh: maple: Robust checking for errors on maple keyboard initialisation

As was pointed out in response to http://lkml.org/lkml/2008/12/19/373
maple drivers were not properly checking for NULL pointers.

This patch fixes this for the keyboard driver already in mainline.

Robust checking for errors on maple keyboard initialisation

Reported-by: Matt Fleming <[email protected]>
Signed-off-by: Adrian McMenamin <[email protected]>
---

diff --git a/drivers/input/keyboard/maple_keyb.c b/drivers/input/keyboard/maple_keyb.c
index 22f17a5..9133af8 100644
--- a/drivers/input/keyboard/maple_keyb.c
+++ b/drivers/input/keyboard/maple_keyb.c
@@ -159,22 +159,41 @@ static void dc_kbd_callback(struct mapleq *mq)

static int probe_maple_kbd(struct device *dev)
{
- struct maple_device *mdev = to_maple_dev(dev);
- struct maple_driver *mdrv = to_maple_driver(dev->driver);
+ struct maple_device *mdev;
+ struct maple_driver *mdrv;
int i, error;
struct dc_kbd *kbd;
struct input_dev *idev;

- if (!(mdev->function & MAPLE_FUNC_KEYBOARD))
- return -EINVAL;
+ mdev = to_maple_dev(dev);
+ if (!mdev) {
+ error = EINVAL;
+ goto fail;
+ }
+
+ mdrv = to_maple_driver(dev->driver);
+ if (!mdrv) {
+ error = EINVAL;
+ goto fail;
+ }
+
+ if (!(mdev->function & MAPLE_FUNC_KEYBOARD)) {
+ error = EINVAL;
+ goto fail;
+ }

kbd = kzalloc(sizeof(struct dc_kbd), GFP_KERNEL);
- idev = input_allocate_device();
- if (!kbd || !idev) {
- error = -ENOMEM;
+ if (!kbd) {
+ error = ENOMEM;
goto fail;
}

+ idev = input_allocate_device();
+ if (!idev) {
+ error = ENOMEM;
+ goto fail_idev_alloc;
+ }
+
kbd->dev = idev;
memcpy(kbd->keycode, dc_kbd_keycode, sizeof(kbd->keycode));

@@ -195,7 +214,7 @@ static int probe_maple_kbd(struct device *dev)

error = input_register_device(idev);
if (error)
- goto fail;
+ goto fail_register;

/* Maple polling is locked to VBLANK - which may be just 50/s */
maple_getcond_callback(mdev, dc_kbd_callback, HZ/50,
@@ -207,11 +226,13 @@ static int probe_maple_kbd(struct device *dev)

return error;

-fail:
+fail_register:
+ maple_set_drvdata(mdev, NULL);
input_free_device(idev);
+fail_idev_alloc:
kfree(kbd);
- maple_set_drvdata(mdev, NULL);
- return error;
+fail:
+ return -error;
}

static int remove_maple_kbd(struct device *dev)


2008-12-21 06:17:54

by Dmitry Torokhov

[permalink] [raw]
Subject: Re: [PATCH] sh: maple: Robust checking for errors on maple keyboard initialisation

On Saturday 20 December 2008 10:25:27 Adrian McMenamin wrote:
> As was pointed out in response to http://lkml.org/lkml/2008/12/19/373
> maple drivers were not properly checking for NULL pointers.
>
> This patch fixes this for the keyboard driver already in mainline.
>

This driver is fine as is, only the joystick driver had the issue.

--
Dmitry

2008-12-24 16:14:51

by Mike Frysinger

[permalink] [raw]
Subject: Re: [PATCH] sh: maple: Robust checking for errors on maple keyboard initialisation

On Saturday 20 December 2008 13:25:27 Adrian McMenamin wrote:
> - maple_set_drvdata(mdev, NULL);
> - return error;
> +fail:
> + return -error;

same comment as for the joystick driver ... it's weird and i'm pretty sure
incorrect due to other functions setting error as well as this driver.
-mike


Attachments:
(No filename) (297.00 B)
signature.asc (835.00 B)
This is a digitally signed message part.
Download all attachments