From patchwork Thu Sep 4 12:01:22 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 36688 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-pa0-f69.google.com (mail-pa0-f69.google.com [209.85.220.69]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 654CE202E4 for ; Thu, 4 Sep 2014 12:02:27 +0000 (UTC) Received: by mail-pa0-f69.google.com with SMTP id kx10sf92176568pab.0 for ; Thu, 04 Sep 2014 05:02:26 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:sender:precedence:list-id :x-original-sender:x-original-authentication-results:mailing-list :list-post:list-help:list-archive:list-unsubscribe; bh=uJO7+sc5DkRCrmSYMFzC7149aWI+IHan4zzaQg+rETk=; b=ig0SzJbKh62fO/4PD1U5AwFAZPbJvjAa6SyoLU2kVH86QH8nHoVR+/DUNWBU50USFH gh32Zi+KPdcUJdQiSz/mNuKCgFTsX3l96bBMtUoVRlYxf1FJlLo46st5wjYw4JvtNFNH 5y1cIdj9IjJopKhi5rd5Afgk9p7mBay60Snoa9kZ6alW00lBh6Ep6cPFY+1HeG6b5Dw2 KJu057akHJQpnLPP/+mfy/o/yZjPgtPGUTopA+BlY3fIjpNeb+La9thvnMTO4S4vWrPo //EvQqT6XZzdcWb2sWtZ/XZP78YrDpNE6YhPTGUnn+t+D52ipoocntNY6Cl0Xl2gNzs+ cg7A== X-Gm-Message-State: ALoCoQkZ8hW2/X0sE/EmxzA4gBzjP0NuBaP/zFB6VxAORbMriAyHo4OWWP+RbzsDAOmCbKhAVlTM X-Received: by 10.70.37.41 with SMTP id v9mr2198237pdj.0.1409832146569; Thu, 04 Sep 2014 05:02:26 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.93.34 with SMTP id c31ls238330qge.92.gmail; Thu, 04 Sep 2014 05:02:26 -0700 (PDT) X-Received: by 10.220.77.65 with SMTP id f1mr477813vck.48.1409832146439; Thu, 04 Sep 2014 05:02:26 -0700 (PDT) Received: from mail-vc0-f172.google.com (mail-vc0-f172.google.com [209.85.220.172]) by mx.google.com with ESMTPS id ac6si2718416vdc.47.2014.09.04.05.02.26 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 04 Sep 2014 05:02:26 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.172 as permitted sender) client-ip=209.85.220.172; Received: by mail-vc0-f172.google.com with SMTP id ij19so10624259vcb.3 for ; Thu, 04 Sep 2014 05:02:26 -0700 (PDT) X-Received: by 10.52.129.165 with SMTP id nx5mr1744877vdb.25.1409832146343; Thu, 04 Sep 2014 05:02:26 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.221.45.67 with SMTP id uj3csp824222vcb; Thu, 4 Sep 2014 05:02:25 -0700 (PDT) X-Received: by 10.70.59.104 with SMTP id y8mr8017690pdq.1.1409832145466; Thu, 04 Sep 2014 05:02:25 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id lp3si3076549pab.230.2014.09.04.05.02.15 for ; Thu, 04 Sep 2014 05:02:15 -0700 (PDT) Received-SPF: none (google.com: linux-pm-owner@vger.kernel.org does not designate permitted sender hosts) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753807AbaIDMCD (ORCPT + 15 others); Thu, 4 Sep 2014 08:02:03 -0400 Received: from mail-pa0-f48.google.com ([209.85.220.48]:48260 "EHLO mail-pa0-f48.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753774AbaIDMCC (ORCPT ); Thu, 4 Sep 2014 08:02:02 -0400 Received: by mail-pa0-f48.google.com with SMTP id ey11so19970359pad.21 for ; Thu, 04 Sep 2014 05:02:01 -0700 (PDT) X-Received: by 10.66.246.109 with SMTP id xv13mr7777276pac.144.1409832121379; Thu, 04 Sep 2014 05:02:01 -0700 (PDT) Received: from localhost ([122.167.123.172]) by mx.google.com with ESMTPSA id ig4sm1526518pbb.55.2014.09.04.05.01.59 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Thu, 04 Sep 2014 05:02:00 -0700 (PDT) From: Viresh Kumar To: sre@kernel.org, dbaryshkov@gmail.com, dwmw2@infradead.org, anton@enomsg.org Cc: linux-pm@vger.kernel.org, linaro-kernel@lists.linaro.org, Viresh Kumar Subject: [PATCH 01/15] power-supply: Don't over-allocate memory for "supplied-from" array Date: Thu, 4 Sep 2014 17:31:22 +0530 Message-Id: <2eacd908a8094887cc1796f75ae0513be8a3e36d.1409831636.git.viresh.kumar@linaro.org> X-Mailer: git-send-email 2.0.3.693.g996b0fd In-Reply-To: References: Sender: linux-pm-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: viresh.kumar@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.172 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , In routine power_supply_check_supplies(), 'cnt' is counting the number of supplies passed in "power-supplies" field of a node. The value of 'cnt' will always be one more than the number of supplies after the do-while loop ends. And so we need to allocate memory for 'cnt - 1' char pointers. But we are allocating memory for 'cnt' instead. Fix this by not over-allocating memory. Signed-off-by: Viresh Kumar --- drivers/power/power_supply_core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/power/power_supply_core.c b/drivers/power/power_supply_core.c index 078afd6..10f0b57 100644 --- a/drivers/power/power_supply_core.c +++ b/drivers/power/power_supply_core.c @@ -234,7 +234,7 @@ static int power_supply_check_supplies(struct power_supply *psy) return -ENOMEM; } - *psy->supplied_from = devm_kzalloc(psy->dev, sizeof(char *) * cnt, + *psy->supplied_from = devm_kzalloc(psy->dev, sizeof(char *) * (cnt - 1), GFP_KERNEL); if (!*psy->supplied_from) { dev_err(psy->dev, "Couldn't allocate memory for supply list\n");