diff options
author | Li Zefan <lizf@cn.fujitsu.com> | 2007-11-14 05:31:05 -0500 |
---|---|---|
committer | Jiri Kosina <jkosina@suse.cz> | 2008-01-28 08:51:19 -0500 |
commit | 3ba5619f06300cd0944150901ed20de87483ad8c (patch) | |
tree | 2fab950f6766fc7c5d2242ac6063ee92c4e8e546 /drivers/hid/usbhid/hid-tmff.c | |
parent | c80e5ffac0579499ca28444155118ffcdd9b8d7e (diff) |
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>
Diffstat (limited to 'drivers/hid/usbhid/hid-tmff.c')
-rw-r--r-- | drivers/hid/usbhid/hid-tmff.c | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/drivers/hid/usbhid/hid-tmff.c b/drivers/hid/usbhid/hid-tmff.c index 69882a726e99..144578b1a00c 100644 --- a/drivers/hid/usbhid/hid-tmff.c +++ b/drivers/hid/usbhid/hid-tmff.c | |||
@@ -137,7 +137,8 @@ static int hid_tmff_play(struct input_dev *dev, void *data, struct ff_effect *ef | |||
137 | int hid_tmff_init(struct hid_device *hid) | 137 | int hid_tmff_init(struct hid_device *hid) |
138 | { | 138 | { |
139 | struct tmff_device *tmff; | 139 | struct tmff_device *tmff; |
140 | struct list_head *pos; | 140 | struct hid_report *report; |
141 | struct list_head *report_list; | ||
141 | struct hid_input *hidinput = list_entry(hid->inputs.next, struct hid_input, list); | 142 | struct hid_input *hidinput = list_entry(hid->inputs.next, struct hid_input, list); |
142 | struct input_dev *input_dev = hidinput->input; | 143 | struct input_dev *input_dev = hidinput->input; |
143 | const signed short *ff_bits = ff_joystick; | 144 | const signed short *ff_bits = ff_joystick; |
@@ -149,8 +150,8 @@ int hid_tmff_init(struct hid_device *hid) | |||
149 | return -ENOMEM; | 150 | return -ENOMEM; |
150 | 151 | ||
151 | /* Find the report to use */ | 152 | /* Find the report to use */ |
152 | list_for_each(pos, &hid->report_enum[HID_OUTPUT_REPORT].report_list) { | 153 | report_list = &hid->report_enum[HID_OUTPUT_REPORT].report_list; |
153 | struct hid_report *report = (struct hid_report *)pos; | 154 | list_for_each_entry(report, report_list, list) { |
154 | int fieldnum; | 155 | int fieldnum; |
155 | 156 | ||
156 | for (fieldnum = 0; fieldnum < report->maxfield; ++fieldnum) { | 157 | for (fieldnum = 0; fieldnum < report->maxfield; ++fieldnum) { |