Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp1828819imm; Mon, 3 Sep 2018 10:29:44 -0700 (PDT) X-Google-Smtp-Source: ANB0VdZwtAvLil8EhovVxN7mthqMKnjG8EfLxrA5BiHs4QaMOvuUr7coBGS4TEudbyssG/h/9Wwa X-Received: by 2002:a17:902:bd4a:: with SMTP id b10-v6mr29744515plx.209.1535995784129; Mon, 03 Sep 2018 10:29:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1535995784; cv=none; d=google.com; s=arc-20160816; b=BxbCjBjXSKQQpp4v/8pQpq2Myf5fe9SQ7MvWyV/WesfLfVQ1BantMQhL6j4ecMymUT jrcFaqo9OknVbuZLfSD5CnCHdbhQJD8nxPaO/cGUvEs/+vpndh2YGLwpdUAHyPcZxJP4 uGZyR/BHfE/zasorRbNF+uiJtWKVxMXwPzrHAGpRjh+rj7NpUWQOfTRvcQ/k0sibMS5y 0a2gebAhqdpB4PF+Kn5D/QF5QNSUiv+KgusfoyEeiV/KWODeXplW97x4lvWl6a+Y2NW9 1q8Lla7Sd+EswzgGzfJEvYb9XMwQOw+NMk/kzxywShEIMyJdV6jWfjnJLL61fckTl8EL 5+yQ== 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=7MaFx3li36EXjDiEuQmxSigL9eOnp+Yh/1D8Ar5VNAs=; b=ZzoVr5sIT+kyemR2lqaV02vqAakE16cQEhlZ5IOhbnZs5I4avhuEoDc+PTxN7iDuDg Ni1+2lwISCuHDxqqz4PitRERoTMdDnngbBYtJvnSW1j4Ci2wnLUERSmll+R4ALA5HK/S AaYF441matEHcj1RAbHNkdHHKhta9SQ+CK+vdDaCEYCjS8LdJy5mnSACesdaIR5ZeMdr 590nppq21e96kcUjs3l30xJ2tNXGmNuuDNgJw1lJ0YFhz8cXKunoa6aaDV5OQt9SymYa Qq9c1exhTwWODQayhZuXj5jNiMzOc/1V0Wf4NC8emf7OGwtBpKvMmNa8dBkpef5UEjvw LJhQ== 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 d30-v6si19980260pld.452.2018.09.03.10.29.28; Mon, 03 Sep 2018 10:29:44 -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 S1730891AbeICVtX (ORCPT + 99 others); Mon, 3 Sep 2018 17:49:23 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:46398 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728175AbeICVtW (ORCPT ); Mon, 3 Sep 2018 17:49:22 -0400 Received: from localhost (ip-213-127-74-90.ip.prioritytelecom.net [213.127.74.90]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id C7BB8CF4; Mon, 3 Sep 2018 17:28:14 +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.14 161/165] power: generic-adc-battery: check for duplicate properties copied from iio channels Date: Mon, 3 Sep 2018 18:57:27 +0200 Message-Id: <20180903165705.171650594@linuxfoundation.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180903165655.003605184@linuxfoundation.org> References: <20180903165655.003605184@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.14-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 @@ -246,6 +246,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) { @@ -292,12 +293,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; }