From patchwork Tue Jun 26 13:28:30 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "H. Nikolaus Schaller" X-Patchwork-Id: 10489073 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 66792602D8 for ; Tue, 26 Jun 2018 13:34:55 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 57F3A287CC for ; Tue, 26 Jun 2018 13:34:55 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4B4042892E; Tue, 26 Jun 2018 13:34:55 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0750A287CC for ; Tue, 26 Jun 2018 13:34:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S935643AbeFZNey (ORCPT ); Tue, 26 Jun 2018 09:34:54 -0400 Received: from mo4-p02-ob.smtp.rzone.de ([85.215.255.84]:21578 "EHLO mo4-p02-ob.smtp.rzone.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934791AbeFZNex (ORCPT ); Tue, 26 Jun 2018 09:34:53 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1530020092; s=strato-dkim-0002; d=goldelico.com; h=References:In-Reply-To:References:In-Reply-To:Message-Id:Date: Subject:Cc:To:From:X-RZG-CLASS-ID:X-RZG-AUTH:From:Subject:Sender; bh=KEXh2wrpKnbaZv7uy1mcGyMrhPGsHvY9+oQ4xhsk9/Q=; b=PVEVeyqcL+dJicH2mPM7GHMR6GFrIOQ4Te+isQbx0jhFsiHw01BRwqdSOGpy7Mn35Y 3bNcvYbz69pnIhzgtnzW+m0S6iOcsR6nphoPDfPrVGnG8uFCshswTRAo/B3qmb6+UkDi iTqNL/R+M9WuGX85bmQSHGJso3cJauQC440HPl9la4Fuw/xlc5mUcI8Lqa2p78Ez6xmD 7F9O/s4VLpLv5q8D6t4jJabExL6shJLjvM9kq1Ey2t5JJ2NQiSqcYHcV+iUAFb7E8U19 u9sumiINuw8pEHxj52oY1C36HUods0dl+NbomTpq32OmkNcYsFIAFu7sE3sp0c1NqSYs ZQjA== X-RZG-AUTH: ":JGIXVUS7cutRB/49FwqZ7WcJeFKiMhflhwDubTJ9o12DNO4Ij0JfyqA2nA==" X-RZG-CLASS-ID: mo00 Received: from iMac.fritz.box by smtp.strato.de (RZmta 43.10 DYNA|AUTH) with ESMTPSA id L06bd3u5QDSWNPw (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (curve secp521r1 with 521 ECDH bits, eq. 15360 bits RSA)) (Client did not present a certificate); Tue, 26 Jun 2018 15:28:32 +0200 (CEST) From: "H. Nikolaus Schaller" To: Sebastian Reichel , anish kumar , Krzysztof Kozlowski , Anton Vorontsov , Jonathan Cameron Cc: linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, letux-kernel@openphoenux.org, kernel@pyra-handheld.com, "H. Nikolaus Schaller" , stable@vger.kernel.org Subject: [PATCH 2/2] power: generic-adc-battery: check for duplicate properties copied from iio channels Date: Tue, 26 Jun 2018 15:28:30 +0200 Message-Id: <0df4d5dc7d3591b8341dba50481d10fbb201fa9d.1530019688.git.hns@goldelico.com> X-Mailer: git-send-email 2.12.2 In-Reply-To: References: In-Reply-To: References: Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 Cc: stable@vger.kernel.org --- drivers/power/supply/generic-adc-battery.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/drivers/power/supply/generic-adc-battery.c b/drivers/power/supply/generic-adc-battery.c index 11f59275bff4..bc462d1ec963 100644 --- a/drivers/power/supply/generic-adc-battery.c +++ b/drivers/power/supply/generic-adc-battery.c @@ -244,6 +244,7 @@ static int gab_probe(struct platform_device *pdev) int ret = 0; int chan; int index = ARRAY_SIZE(gab_props); + bool any = false; adc_bat = devm_kzalloc(&pdev->dev, sizeof(*adc_bat), GFP_KERNEL); if (!adc_bat) { @@ -290,12 +291,22 @@ static int gab_probe(struct platform_device *pdev) adc_bat->channel[chan] = NULL; } else { /* copying properties for supported channels only */ - psy_desc->properties[index++] = gab_dyn_props[chan]; + int index2; + + for (index2 = 0; index2 < index; index2++) { + if (psy_desc->properties[index2] == + gab_dyn_props[chan]) + break; /* already known */ + } + if (index2 == index) /* really new */ + psy_desc->properties[index++] = + gab_dyn_props[chan]; + any = true; } } /* none of the channels are supported so let's bail out */ - if (index == ARRAY_SIZE(gab_props)) { + if (!any) { ret = -ENODEV; goto second_mem_fail; }