Skip to content

Commit

Permalink
compal-laptop: Use devm_kzalloc to allocate local data structure
Browse files Browse the repository at this point in the history
Reduce code size and simplify error path.

Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Matthew Garrett <matthew.garrett@nebula.com>
  • Loading branch information
Guenter Roeck authored and Matthew Garrett committed Jan 21, 2014
1 parent 7da8fb2 commit cf508f4
Showing 1 changed file with 2 additions and 7 deletions.
9 changes: 2 additions & 7 deletions drivers/platform/x86/compal-laptop.c
Original file line number Diff line number Diff line change
Expand Up @@ -1026,24 +1026,21 @@ static int compal_probe(struct platform_device *pdev)
return 0;

/* Fan control */
data = kzalloc(sizeof(struct compal_data), GFP_KERNEL);
data = devm_kzalloc(&pdev->dev, sizeof(struct compal_data), GFP_KERNEL);
if (!data)
return -ENOMEM;

initialize_fan_control_data(data);

err = sysfs_create_group(&pdev->dev.kobj, &compal_attribute_group);
if (err) {
kfree(data);
if (err)
return err;
}

data->hwmon_dev = hwmon_device_register(&pdev->dev);
if (IS_ERR(data->hwmon_dev)) {
err = PTR_ERR(data->hwmon_dev);
sysfs_remove_group(&pdev->dev.kobj,
&compal_attribute_group);
kfree(data);
return err;
}

Expand Down Expand Up @@ -1083,8 +1080,6 @@ static int compal_remove(struct platform_device *pdev)
hwmon_device_unregister(data->hwmon_dev);
power_supply_unregister(&data->psy);

kfree(data);

sysfs_remove_group(&pdev->dev.kobj, &compal_attribute_group);

return 0;
Expand Down

0 comments on commit cf508f4

Please sign in to comment.