diff options
author | Lee Jones <lee.jones@linaro.org> | 2014-08-18 08:10:20 -0400 |
---|---|---|
committer | Lee Jones <lee.jones@linaro.org> | 2014-09-26 03:15:31 -0400 |
commit | 9b6a5ad9da4118e8c2a087501ddff33f51a9e6ba (patch) | |
tree | 702d8cf37bd598622b9cd86ec59c1d002d0d4559 /drivers/mfd/htc-i2cpld.c | |
parent | 41cc08e955187b96867fa0f625c55496961699ba (diff) |
mfd: htc-i2cpld: Rectify pointer offset error
Checking the result of container_of() against NULL will always result to
false. Using the offset of member 'chip_out' to find the start of 'struct
htcpld_chip' will result in an offset error when .get_chip() is attempting
to obtain 'htcpld-in'. Instead, we'll use the correct member based on a
previously the set chip label.
Signed-off-by: Lee Jones <lee.jones@linaro.org>
Diffstat (limited to 'drivers/mfd/htc-i2cpld.c')
-rw-r--r-- | drivers/mfd/htc-i2cpld.c | 33 |
1 files changed, 10 insertions, 23 deletions
diff --git a/drivers/mfd/htc-i2cpld.c b/drivers/mfd/htc-i2cpld.c index 073e1801cdab..99b362e43329 100644 --- a/drivers/mfd/htc-i2cpld.c +++ b/drivers/mfd/htc-i2cpld.c | |||
@@ -258,31 +258,18 @@ static void htcpld_chip_set_ni(struct work_struct *work) | |||
258 | static int htcpld_chip_get(struct gpio_chip *chip, unsigned offset) | 258 | static int htcpld_chip_get(struct gpio_chip *chip, unsigned offset) |
259 | { | 259 | { |
260 | struct htcpld_chip *chip_data; | 260 | struct htcpld_chip *chip_data; |
261 | int val = 0; | 261 | u8 cache; |
262 | int is_input = 0; | ||
263 | |||
264 | /* Try out first */ | ||
265 | chip_data = container_of(chip, struct htcpld_chip, chip_out); | ||
266 | if (!chip_data) { | ||
267 | /* Try in */ | ||
268 | is_input = 1; | ||
269 | chip_data = container_of(chip, struct htcpld_chip, chip_in); | ||
270 | if (!chip_data) | ||
271 | return -EINVAL; | ||
272 | } | ||
273 | 262 | ||
274 | /* Determine if this is an input or output GPIO */ | 263 | if (!strncmp(chip->label, "htcpld-out", 10)) { |
275 | if (!is_input) | 264 | chip_data = container_of(chip, struct htcpld_chip, chip_out); |
276 | /* Use the output cache */ | 265 | cache = chip_data->cache_out; |
277 | val = (chip_data->cache_out >> offset) & 1; | 266 | } else if (!strncmp(chip->label, "htcpld-in", 9)) { |
278 | else | 267 | chip_data = container_of(chip, struct htcpld_chip, chip_in); |
279 | /* Use the input cache */ | 268 | cache = chip_data->cache_in; |
280 | val = (chip_data->cache_in >> offset) & 1; | 269 | } else |
270 | return -EINVAL; | ||
281 | 271 | ||
282 | if (val) | 272 | return (cache >> offset) & 1; |
283 | return 1; | ||
284 | else | ||
285 | return 0; | ||
286 | } | 273 | } |
287 | 274 | ||
288 | static int htcpld_direction_output(struct gpio_chip *chip, | 275 | static int htcpld_direction_output(struct gpio_chip *chip, |