HID: wacom: Fix error path of power-supply initialization
PATCH 1/2 HID: wacom: Fix error path of power-supply initialization
power_supply_unregister() must not be called if power_supply_register() failed. The wdata->psy.dev pointer may point to invalid memory after a failed power_supply_register() and hence wacom_remove() will fail while calling power_supply_unregister().
This changes the wacom_probe function to fail if it cannot register the power_supply devices. If we would want to keep the previous behaviour we had to keep some flag about the power_supply state and check it on wacom_remove, but this seems inappropriate here. Hence, we simply fail, too, if power_supply_register fails.
--- drivers/hid/hid-wacom.c | 21 +++++++++------------ 1 files changed, 9 insertions(+), 12 deletions(-)
drivers/hid/hid-wacom.c +9 -12
@@ -353,11 +353,7 @@ static int wacom_probe(struct hid_device *hdev,if (ret) {hid_warn (hdev,"can't create sysfs battery attribute, err: %d\n" , ret); -/* -* battery attribute is not critical for the tablet, but if it -* failed then there is no need to create ac attribute -*/ - goto move_on; + goto err_battery; } wdata->ac.properties = wacom_ac_props;
@@ -371,14 +367,8 @@ static int wacom_probe(struct hid_device *hdev,if (ret) {hid_warn (hdev,"can't create ac battery attribute, err: %d\n" , ret); -/* -* ac attribute is not critical for the tablet, but if it -* failed then we don't want to battery attribute to exist -*/ -power_supply_unregister (&wdata->battery); + goto err_ac; } - -move_on:#endif hidinput = list_entry(hdev->inputs.next, struct hid_input, list); input = hidinput->input;
@@ -416,6 +406,13 @@ move_on:return 0 ; +#ifdef CONFIG_HID_WACOM_POWER_SUPPLY +err_ac: +power_supply_unregister (&wdata->battery); +err_battery: +device_remove_file (&hdev->dev, &dev_attr_speed); +hid_hw_stop (hdev); +#endif err_free:kfree (wdata);return ret;
Signature · 1 line
1.7.6.1
PATCH 2/2 HID: wacom: Unregister sysfs attributes on remove
HID devices can be hotplugged so we should unregister all sysfs attributes when removing a driver. Otherwise, manually unloading the wacom-driver will not remove the sysfs attributes. Only when the device is disconnected, they are removed, eventually.
--- drivers/hid/hid-wacom.c | 1 + 1 files changed, 1 insertions(+), 0 deletions(-)
drivers/hid/hid-wacom.c +1 -0
@@ -423,6 +423,7 @@ static void wacom_remove(struct hid_device *hdev)#ifdef CONFIG_HID_WACOM_POWER_SUPPLY struct wacom_data *wdata =hid_get_drvdata (hdev);#endif +device_remove_file (&hdev->dev, &dev_attr_speed);hid_hw_stop (hdev);#ifdef CONFIG_HID_WACOM_POWER_SUPPLY
Signature · 1 line
1.7.6.1
Jiri Kosina
AppliedQuoted 5 lines · David Herrmann
power_supply_unregister()must not be called ifpower_supply_register()failed. Thewdata->psy.devpointer may point to invalid memory after a failedpower_supply_register()and hencewacom_remove()will fail while callingpower_supply_unregister().
Quoted 7 lines
This changes the
wacom_probefunction to fail if it cannot register thepower_supplydevices. If we would want to keep the previous behaviour we had to keep some flag about thepower_supplystate and check it onwacom_remove, but this seems inappropriate here. Hence, we simply fail, too, ifpower_supply_registerfails.Signed-off-by David Herrmann <[email protected]>
Applied, thanks.
Quoted 54 lines
--- drivers/hid/hid-wacom.c | 21 +++++++++------------ 1 files changed, 9 insertions(+), 12 deletions(-)drivers/hid/hid-wacom.c +9
-12@@ -353,11 +353,7 @@ static int wacom_probe(struct hid_device *hdev,if (ret) {hid_warn (hdev,"can't create sysfs battery attribute, err: %d\n" , ret); -/* -* battery attribute is not critical for the tablet, but if it -* failed then there is no need to create ac attribute -*/ - goto move_on; + goto err_battery; } wdata->ac.properties = wacom_ac_props;@@ -371,14 +367,8 @@ static int wacom_probe(struct hid_device *hdev,if (ret) {hid_warn (hdev,"can't create ac battery attribute, err: %d\n" , ret); -/* -* ac attribute is not critical for the tablet, but if it -* failed then we don't want to battery attribute to exist -*/ -power_supply_unregister (&wdata->battery); + goto err_ac; } - -move_on:#endif hidinput = list_entry(hdev->inputs.next, struct hid_input, list); input = hidinput->input;@@ -416,6 +406,13 @@ move_on:return 0 ; +#ifdef CONFIG_HID_WACOM_POWER_SUPPLY +err_ac: +power_supply_unregister (&wdata->battery); +err_battery: +device_remove_file (&hdev->dev, &dev_attr_speed); +hid_hw_stop (hdev); +#endif err_free:kfree (wdata);return ret;Signature · 1 line
1.7.6.1
Signature · 2 lines
Jiri Kosina SUSE Labs
Jiri Kosina
AppliedRe: [PATCH 2/2] HID: wacom: Unregister sysfs attributes on remove
In reply to David HerrmannQuoted 6 lines · David Herrmann
HID devices can be hotplugged so we should unregister all sysfs attributes when removing a driver. Otherwise, manually unloading the wacom-driver will not remove the sysfs attributes. Only when the device is disconnected, they are removed, eventually.
Signed-off-by David Herrmann <[email protected]>
Applied, thanks David.
Quoted 19 lines
--- drivers/hid/hid-wacom.c | 1 + 1 files changed, 1 insertions(+), 0 deletions(-)drivers/hid/hid-wacom.c +1
-0@@ -423,6 +423,7 @@ static void wacom_remove(struct hid_device *hdev)#ifdef CONFIG_HID_WACOM_POWER_SUPPLY struct wacom_data *wdata =hid_get_drvdata (hdev);#endif +device_remove_file (&hdev->dev, &dev_attr_speed);hid_hw_stop (hdev);#ifdef CONFIG_HID_WACOM_POWER_SUPPLY Signature · 1 line
1.7.6.1
Signature · 2 lines
Jiri Kosina SUSE Labs