Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp3809112pxa; Sun, 9 Aug 2020 12:24:47 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzAkscI3mOyX9gQE4kugWA2HcQl6HInMJMHHCVKjuMYO4bzps+5e0N0F3Ucet2n6wacHH8y X-Received: by 2002:a17:906:c2c8:: with SMTP id ch8mr18154707ejb.161.1597001086812; Sun, 09 Aug 2020 12:24:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597001086; cv=none; d=google.com; s=arc-20160816; b=q6EBt+FZqGvpcaWvFIUajr4iNQqANLJpFWpZMqwW2N5fMhiAwEdvrMcyp0B15m4zex C11mJUMrhOJgcDBlz0E1MDQA9Q9aJHNtWg226d8ZL85mExxGK/oA77RsjdSxx44Q7b/d ozKsb9upS5X2RS4zrYDSX9qrw7pKIEGJCzGIEIoAdY8HRg6BNXiY+IHHsNwIIPRNOO91 C2KXU47QJkbwOyPjaGVyDVt6/n1AgDA4bfaHpwAHb4Ms/t1HJ4n4cXsz62Gf8VJmMrT0 qnrHIiN3YIYF4ZEGQ1M1KHrbNKMN1IfFfgl6cdo5rz4Jz1GYbBs86+m5Xg0tsCGSw8lK 9dQA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:content-transfer-encoding :mime-version:subject:from:message-id:date:dkim-signature; bh=HmV6r+iiy8YC1+I7xjUtNE207JPXzzgN0C3QwDyK5Io=; b=QoD7nBUDubqWjxi4Ii1XizjjgAz5RmMQagmOx2CM6x+esbOD3PL5mEp9ks7im/4fA9 ALejzrPxdHI13a6bW8SX9hBzWl6PhyaXD7EKYUdXNj/ZM36I2PRamKVYWDP0O39wnv6N qQ/xiYT0DkU+QcEsbBnLPj6o92kcXNKZ3QJwFfGi3U7etoIia4DI7A8YCTjnP6beCfof Nyp2bf5lKAInXUKKk/kjcE7iAvlP+HINFlLMjuAYg85WjkUbc1uR6brSqwlKjNo2bpmK h33/YdQAvBF8G9rOz64zBMljQ6hAmkIg0gwzkLdvCNq2loB0Ow1SpkGLh3ga75sdnYvv ee8w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@rere.qmqm.pl header.s=1 header.b=qIKRRntN; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id o19si9699587ejh.268.2020.08.09.12.24.23; Sun, 09 Aug 2020 12:24:46 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@rere.qmqm.pl header.s=1 header.b=qIKRRntN; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726307AbgHITVV (ORCPT + 99 others); Sun, 9 Aug 2020 15:21:21 -0400 Received: from rere.qmqm.pl ([91.227.64.183]:37343 "EHLO rere.qmqm.pl" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726289AbgHITVV (ORCPT ); Sun, 9 Aug 2020 15:21:21 -0400 Received: from remote.user (localhost [127.0.0.1]) by rere.qmqm.pl (Postfix) with ESMTPSA id 4BPpqM0Gb7z8y; Sun, 9 Aug 2020 21:21:18 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=rere.qmqm.pl; s=1; t=1597000879; bh=FxMu9VKYnSAZULnqvFb3SCOZdO1jmVriVZ6iSkttly8=; h=Date:From:Subject:To:Cc:From; b=qIKRRntNOToqP1ljPJT9nGdBdhkiCLDarT1hpSi1qIhoYtDqnNw3QZrmqqssTCIFy ko6h+CcVOenKnoYq2FcIZTZbQxZH+4MxWN2kXndPYockkbkszK6DseLwflLMVGhENE 027zbVK+JPQH4tGIL/LbwFgodSghXlNEeBiF82WjfK5MWR4W2hLCm1HJ0VR/UU6fJQ EfITIoiwIOqVyCD0Z/o50hYhx3RL8bYaKyyRJwLf2j5iuGKbtzf0WTFgMTSa5CZerQ dwp2XyCfw9Ek7/BpQi7YS8nOLJyBQAnnIpJ7KWymLuFAecT5pvUBpkpxOrkloP1xy+ 9b50VfUNr7UqQ== X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.102.4 at mail Date: Sun, 09 Aug 2020 21:21:16 +0200 Message-Id: <407fbd06a02caf038a9ba3baa51c7d6d47cd6517.1597000795.git.mirq-linux@rere.qmqm.pl> From: =?UTF-8?q?Micha=C5=82=20Miros=C5=82aw?= Subject: [PATCH] regulator: fix pointer table overallocation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit To: Dmitry Osipenko , Liam Girdwood , Mark Brown Cc: linux-kernel@vger.kernel.org Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The code allocates sizeof(regulator_dev) for a pointer. Make it less generous. Let kcalloc() calculate the size, while at it. Cc: stable@vger.kernel.org Fixes: d8ca7d184b33 ("regulator: core: Introduce API for regulators coupling customization") Signed-off-by: Michał Mirosław --- drivers/regulator/core.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c index 75ff7c563c5d..9e18997777d3 100644 --- a/drivers/regulator/core.c +++ b/drivers/regulator/core.c @@ -5011,20 +5011,20 @@ static void regulator_remove_coupling(struct regulator_dev *rdev) static int regulator_init_coupling(struct regulator_dev *rdev) { + struct regulator_dev **coupled; int err, n_phandles; - size_t alloc_size; if (!IS_ENABLED(CONFIG_OF)) n_phandles = 0; else n_phandles = of_get_n_coupled(rdev); - alloc_size = sizeof(*rdev) * (n_phandles + 1); - - rdev->coupling_desc.coupled_rdevs = kzalloc(alloc_size, GFP_KERNEL); - if (!rdev->coupling_desc.coupled_rdevs) + coupled = kcalloc(n_phandles + 1, sizeof(*coupled), GFP_KERNEL); + if (!coupled) return -ENOMEM; + rdev->coupling_desc.coupled_rdevs = coupled; + /* * Every regulator should always have coupling descriptor filled with * at least pointer to itself. -- 2.20.1