Skip to content

Commit f9f6766

Browse files
goldelicogregkh
authored andcommitted
power: generic-adc-battery: check for duplicate properties copied from iio channels
commit a427503 upstream. If an iio channel defines a basic property, there are duplicate entries in /sys/class/power/*/uevent. So add a check to avoid duplicates. Since all channels may be duplicates, we have to modify the related error check. Signed-off-by: H. Nikolaus Schaller <hns@goldelico.com> Cc: stable@vger.kernel.org Fixes: e60fea7 ("power: battery: Generic battery driver using IIO") Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.co.uk> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 54cecb7 commit f9f6766

1 file changed

Lines changed: 13 additions & 2 deletions

File tree

drivers/power/supply/generic-adc-battery.c

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,7 @@ static int gab_probe(struct platform_device *pdev)
246246
int ret = 0;
247247
int chan;
248248
int index = ARRAY_SIZE(gab_props);
249+
bool any = false;
249250

250251
adc_bat = devm_kzalloc(&pdev->dev, sizeof(*adc_bat), GFP_KERNEL);
251252
if (!adc_bat) {
@@ -292,12 +293,22 @@ static int gab_probe(struct platform_device *pdev)
292293
adc_bat->channel[chan] = NULL;
293294
} else {
294295
/* copying properties for supported channels only */
295-
psy_desc->properties[index++] = gab_dyn_props[chan];
296+
int index2;
297+
298+
for (index2 = 0; index2 < index; index2++) {
299+
if (psy_desc->properties[index2] ==
300+
gab_dyn_props[chan])
301+
break; /* already known */
302+
}
303+
if (index2 == index) /* really new */
304+
psy_desc->properties[index++] =
305+
gab_dyn_props[chan];
306+
any = true;
296307
}
297308
}
298309

299310
/* none of the channels are supported so let's bail out */
300-
if (index == ARRAY_SIZE(gab_props)) {
311+
if (!any) {
301312
ret = -ENODEV;
302313
goto second_mem_fail;
303314
}

0 commit comments

Comments
 (0)