Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

HID: intel-ish-hid: fix wrong driver_data usage

Currently, in suspend() and resume(), ishtp client drivers are using
driver_data to get "struct ishtp_cl_device" object which is set by
bus driver. It's wrong since the driver_data should not be owned bus.
driver_data should be owned by the corresponding ishtp client driver.
Due to this, some ishtp client driver like cros_ec_ishtp which uses
its driver_data to transfer its data to its child doesn't work correctly.

So this patch removes setting driver_data in bus drier and instead of
using driver_data to get "struct ishtp_cl_device", since "struct device"
is embedded in "struct ishtp_cl_device", we introduce a helper function
that returns "struct ishtp_cl_device" from "struct device".

Signed-off-by: Hyungwoo Yang <hyungwoo.yang@intel.com>
Acked-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
Signed-off-by: Jiri Kosina <jkosina@suse.cz>

authored by

Hyungwoo Yang and committed by
Jiri Kosina
b12bbdc5 0a95fc73

+17 -3
+2 -2
drivers/hid/intel-ish-hid/ishtp-hid-client.c
··· 899 899 */ 900 900 static int hid_ishtp_cl_suspend(struct device *device) 901 901 { 902 - struct ishtp_cl_device *cl_device = dev_get_drvdata(device); 902 + struct ishtp_cl_device *cl_device = ishtp_dev_to_cl_device(device); 903 903 struct ishtp_cl *hid_ishtp_cl = ishtp_get_drvdata(cl_device); 904 904 struct ishtp_cl_data *client_data = ishtp_get_client_data(hid_ishtp_cl); 905 905 ··· 920 920 */ 921 921 static int hid_ishtp_cl_resume(struct device *device) 922 922 { 923 - struct ishtp_cl_device *cl_device = dev_get_drvdata(device); 923 + struct ishtp_cl_device *cl_device = ishtp_dev_to_cl_device(device); 924 924 struct ishtp_cl *hid_ishtp_cl = ishtp_get_drvdata(cl_device); 925 925 struct ishtp_cl_data *client_data = ishtp_get_client_data(hid_ishtp_cl); 926 926
+14 -1
drivers/hid/intel-ish-hid/ishtp/bus.c
··· 479 479 } 480 480 481 481 ishtp_device_ready = true; 482 - dev_set_drvdata(&device->dev, device); 483 482 484 483 return device; 485 484 } ··· 645 646 return cl_device->driver_data; 646 647 } 647 648 EXPORT_SYMBOL(ishtp_get_drvdata); 649 + 650 + /** 651 + * ishtp_dev_to_cl_device() - get ishtp_cl_device instance from device instance 652 + * @device: device instance 653 + * 654 + * Get ish_cl_device instance which embeds device instance in it. 655 + * 656 + * Return: pointer to ishtp_cl_device instance 657 + */ 658 + struct ishtp_cl_device *ishtp_dev_to_cl_device(struct device *device) 659 + { 660 + return to_ishtp_cl_device(device); 661 + } 662 + EXPORT_SYMBOL(ishtp_dev_to_cl_device); 648 663 649 664 /** 650 665 * ishtp_bus_new_client() - Create a new client
+1
include/linux/intel-ish-client-if.h
··· 103 103 void ishtp_get_device(struct ishtp_cl_device *cl_dev); 104 104 void ishtp_set_drvdata(struct ishtp_cl_device *cl_device, void *data); 105 105 void *ishtp_get_drvdata(struct ishtp_cl_device *cl_device); 106 + struct ishtp_cl_device *ishtp_dev_to_cl_device(struct device *dev); 106 107 int ishtp_register_event_cb(struct ishtp_cl_device *device, 107 108 void (*read_cb)(struct ishtp_cl_device *)); 108 109 struct ishtp_fw_client *ishtp_fw_cl_get_client(struct ishtp_device *dev,