mirror of https://gitee.com/openkylin/linux.git
HID: fix a potential bug in pointer casting
Don't directly cast list_head * to foo *, this works only when list is the first member of struct foo, and we should not make the assumption how members are ordered in the structure. i.e. struct *f = (struct *f)pos will work if: struct foo { struct list_head list; int i; }; but will fail if: struct foo { int i; struct list_head list; } Signed-off-by: Li Zefan <lizf@cn.fujitsu.com> Signed-off-by: Jiri Kosina <jkosina@suse.cz>
This commit is contained in:
parent
c80e5ffac0
commit
3ba5619f06
|
@ -137,7 +137,8 @@ static int hid_tmff_play(struct input_dev *dev, void *data, struct ff_effect *ef
|
||||||
int hid_tmff_init(struct hid_device *hid)
|
int hid_tmff_init(struct hid_device *hid)
|
||||||
{
|
{
|
||||||
struct tmff_device *tmff;
|
struct tmff_device *tmff;
|
||||||
struct list_head *pos;
|
struct hid_report *report;
|
||||||
|
struct list_head *report_list;
|
||||||
struct hid_input *hidinput = list_entry(hid->inputs.next, struct hid_input, list);
|
struct hid_input *hidinput = list_entry(hid->inputs.next, struct hid_input, list);
|
||||||
struct input_dev *input_dev = hidinput->input;
|
struct input_dev *input_dev = hidinput->input;
|
||||||
const signed short *ff_bits = ff_joystick;
|
const signed short *ff_bits = ff_joystick;
|
||||||
|
@ -149,8 +150,8 @@ int hid_tmff_init(struct hid_device *hid)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
|
||||||
/* Find the report to use */
|
/* Find the report to use */
|
||||||
list_for_each(pos, &hid->report_enum[HID_OUTPUT_REPORT].report_list) {
|
report_list = &hid->report_enum[HID_OUTPUT_REPORT].report_list;
|
||||||
struct hid_report *report = (struct hid_report *)pos;
|
list_for_each_entry(report, report_list, list) {
|
||||||
int fieldnum;
|
int fieldnum;
|
||||||
|
|
||||||
for (fieldnum = 0; fieldnum < report->maxfield; ++fieldnum) {
|
for (fieldnum = 0; fieldnum < report->maxfield; ++fieldnum) {
|
||||||
|
|
Loading…
Reference in New Issue