Skip to content

Commit

Permalink
HID: sony: fix error return code
Browse files Browse the repository at this point in the history
Currently the return variable ret is always 0.  Set it to other values in
error cases, as used in the direct return.

A simplified version of the semantic match that finds this problem is as
follows: (http://coccinelle.lip6.fr/)

// <smpl>
(
if@p1 (\(ret < 0\|ret != 0\))
 { ... return ret; }
|
ret@p1 = 0
)
... when != ret = e1
    when != &ret
*if(...)
{
  ... when != ret = e2
      when forall
 return ret;
}

// </smpl>

Signed-off-by: Julia Lawall <Julia.Lawall@lip6.fr>
Signed-off-by: Jiri Kosina <jkosina@suse.cz>
  • Loading branch information
Julia Lawall authored and Jiri Kosina committed Jan 2, 2014
1 parent 0a286ef commit 8cd5fcd
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion drivers/hid/hid-sony.c
Original file line number Diff line number Diff line change
Expand Up @@ -585,6 +585,7 @@ static int sony_leds_init(struct hid_device *hdev)
led = kzalloc(sizeof(struct led_classdev) + name_sz, GFP_KERNEL);
if (!led) {
hid_err(hdev, "Couldn't allocate memory for LED %d\n", n);
ret = -ENOMEM;
goto error_leds;
}

Expand All @@ -596,7 +597,8 @@ static int sony_leds_init(struct hid_device *hdev)
led->brightness_get = sony_led_get_brightness;
led->brightness_set = sony_led_set_brightness;

if (led_classdev_register(&hdev->dev, led)) {
ret = led_classdev_register(&hdev->dev, led);
if (ret) {
hid_err(hdev, "Failed to register LED %d\n", n);
kfree(led);
goto error_leds;
Expand Down

0 comments on commit 8cd5fcd

Please sign in to comment.