Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp1836080imm; Mon, 3 Sep 2018 10:41:01 -0700 (PDT) X-Google-Smtp-Source: ANB0VdbH7s7ivVrmfebpivR4+wZWJVKoCFEQdtQjaTWQcei7YtkTIuliPy6nZIYwd9E+rijzsiHZ X-Received: by 2002:a63:555c:: with SMTP id f28-v6mr27742436pgm.37.1535996461587; Mon, 03 Sep 2018 10:41:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1535996461; cv=none; d=google.com; s=arc-20160816; b=oKrxv6IyEy3omvXETbgHe3JXID49q8xLxqzIYMykGI8uKQIW/txC71lMSonFYKrXsZ XgWZZjS7wnKLoOx56kq2zD0ydxXNUeVqD22lItOvJQfWPS+l5YjB/lojhkVzT5PZQpn1 Ojer9UKFUKb5T0ZIkjumc4OLF2MnsxT4+aUGrSDfTTlWP0nUGlFIir20u8FjWydlUjdn h5qDvfgM3Orqqr0yyLn/edwuqIO8+hBemN3x8/hcvPpyUPRcw7neLS6JqmyXb9/h+EfS DX1ZOcKDz5QG/hfRzAojhCWZDyBbW5tbmBXIt0FOH/74frqsEmyogT2MNXS9F0hRR6Mr QUaQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=an5QSojZm7tXlxCneK7yeMwLtwLz7YfAOkEFmq+AUnY=; b=USUktLFYNxHYRIKq4iNPgAikni2zKqM4Y9Q/A66xYREHU3JV8aEnbE8YQHRlE8YFZs uCc5w6kcYUuPqb9PV6zJFYwNRIHx97y7PVSRFYmKeHIx1Yt4tKIOhSZOjZzDTEyYb/xR pNFa5+Ls5i4GmjPyQVovkev+x3gNB7/IctIYE6OX615P8XFDbZ75bh34r9RkMjZLwurq 3M0th2isFfa9QtkmLmxRvT/LKhwvsxcYL+gL8fMvc3JuLmakbJ6s1HnDUlQYGbcyfxC5 XkQJ2HdxQFDXG0vhVjmvDrR1KOeK4o7JINuPh91SEN5XbOB+06EbkrQBISyI6nu8AgrN HTKw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f190-v6si19162899pfc.327.2018.09.03.10.40.46; Mon, 03 Sep 2018 10:41:01 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731968AbeICWAy (ORCPT + 99 others); Mon, 3 Sep 2018 18:00:54 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:49298 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729170AbeICWAx (ORCPT ); Mon, 3 Sep 2018 18:00:53 -0400 Received: from localhost (ip-213-127-74-90.ip.prioritytelecom.net [213.127.74.90]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 78584A95; Mon, 3 Sep 2018 17:39:42 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, "H. Nikolaus Schaller" , Sebastian Reichel Subject: [PATCH 4.18 119/123] power: generic-adc-battery: check for duplicate properties copied from iio channels Date: Mon, 3 Sep 2018 18:57:43 +0200 Message-Id: <20180903165724.529399534@linuxfoundation.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180903165719.499675257@linuxfoundation.org> References: <20180903165719.499675257@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: H. Nikolaus Schaller commit a427503edaaed9b75ed9746a654cece7e93e60a8 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 Cc: stable@vger.kernel.org Fixes: e60fea794e6e ("power: battery: Generic battery driver using IIO") Signed-off-by: Sebastian Reichel Signed-off-by: Greg Kroah-Hartman --- drivers/power/supply/generic-adc-battery.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) --- 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_dev 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_dev 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; }