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>
This commit is contained in:
parent
41cc08e955
commit
9b6a5ad9da
|
@ -258,31 +258,18 @@ static void htcpld_chip_set_ni(struct work_struct *work)
|
||||||
static int htcpld_chip_get(struct gpio_chip *chip, unsigned offset)
|
static int htcpld_chip_get(struct gpio_chip *chip, unsigned offset)
|
||||||
{
|
{
|
||||||
struct htcpld_chip *chip_data;
|
struct htcpld_chip *chip_data;
|
||||||
int val = 0;
|
u8 cache;
|
||||||
int is_input = 0;
|
|
||||||
|
|
||||||
/* Try out first */
|
if (!strncmp(chip->label, "htcpld-out", 10)) {
|
||||||
chip_data = container_of(chip, struct htcpld_chip, chip_out);
|
chip_data = container_of(chip, struct htcpld_chip, chip_out);
|
||||||
if (!chip_data) {
|
cache = chip_data->cache_out;
|
||||||
/* Try in */
|
} else if (!strncmp(chip->label, "htcpld-in", 9)) {
|
||||||
is_input = 1;
|
|
||||||
chip_data = container_of(chip, struct htcpld_chip, chip_in);
|
chip_data = container_of(chip, struct htcpld_chip, chip_in);
|
||||||
if (!chip_data)
|
cache = chip_data->cache_in;
|
||||||
return -EINVAL;
|
} else
|
||||||
}
|
return -EINVAL;
|
||||||
|
|
||||||
/* Determine if this is an input or output GPIO */
|
return (cache >> offset) & 1;
|
||||||
if (!is_input)
|
|
||||||
/* Use the output cache */
|
|
||||||
val = (chip_data->cache_out >> offset) & 1;
|
|
||||||
else
|
|
||||||
/* Use the input cache */
|
|
||||||
val = (chip_data->cache_in >> offset) & 1;
|
|
||||||
|
|
||||||
if (val)
|
|
||||||
return 1;
|
|
||||||
else
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int htcpld_direction_output(struct gpio_chip *chip,
|
static int htcpld_direction_output(struct gpio_chip *chip,
|
||||||
|
|
Loading…
Reference in New Issue