From patchwork Wed Aug 14 12:54:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 13763466 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 8BE81C52D7B for ; Wed, 14 Aug 2024 12:57:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=2onqNzPpjdxEZo74Prm9VlRvvWEppV1Qf3ow87H51Zo=; b=AHgs19YZsMI3Q/73gbt2SPsj9M o/KtJUnamQfrofYMgWYtjN6YH6H3WuSP4js71GFKRU8a/oRvJA4T3U05EviRaXljhR3FHLgdiQwHI my6GzNOAfmLKJ3PUdO561uB3zGRoRlH7d6iYyvwnNdwFd2VGqnMIjrT4mpwinkZhyj0F2FQNRATS1 3G6L6iN7u6d5GR9j3DOCOeRH/0KiYD87h8RYjvGjfgTtRMZnp5dHi//J8VMJ4XB/bRj9mYTKnhMkl oJtXvBtB+P8NkSWpGtgmD8Yw4EjYyGzTjYv7QZ1D3YinrpZ3+XMdlXWAHrRQchru3gJ3cEdUwBjo0 A6zR/bCw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1seDYu-000000070zx-3B6Q; Wed, 14 Aug 2024 12:57:12 +0000 Received: from mgamail.intel.com ([192.198.163.15]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1seDX5-000000070UY-30bo for linux-arm-kernel@lists.infradead.org; Wed, 14 Aug 2024 12:55:21 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1723640120; x=1755176120; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=lUSmyX8AJAgdUi5lPG1EUFhUfIEx7/D0s/i6MthUHTQ=; b=mSrAzGypNX7jcp57wbvRtnhd81hCOXOsKX6L49qQbRd+wkz6/OOKF7gj U1E/FrIHICwHoRqMJMX5CkBLVrcqN9DugWDVASpdRicnQ59eLwuRJwCNp 5n7ADdIE5d+SRdEKTbb564juAOWJ1nkiX4q8insxo8pcMLKAwIGSxOnXe kP332u3MA2746s5fFOdjRU/aE+bL24FZIf5oTLbVqP6k5K5c1nJusi/ax pFL/M3wOMbNwSPybU/4XbRUUnuxyKj53+RSsOqJNwVHl1D5VivMA82brJ N6o3XH7FQF9BP/anq1rMy6VSHAD2iqIvhpetmCYxWheQUtJGtgJ4E/otn A==; X-CSE-ConnectionGUID: VC0+ShTVToWQGvhsMpQA7w== X-CSE-MsgGUID: vh5YPag6TfKUyo+8o4VGxA== X-IronPort-AV: E=McAfee;i="6700,10204,11164"; a="22010677" X-IronPort-AV: E=Sophos;i="6.10,145,1719903600"; d="scan'208";a="22010677" Received: from fmviesa001.fm.intel.com ([10.60.135.141]) by fmvoesa109.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Aug 2024 05:55:17 -0700 X-CSE-ConnectionGUID: W9vRtWsASGqElq4+BjyMwA== X-CSE-MsgGUID: 3UUnfxD+SMm86zbkydPOpQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.10,145,1719903600"; d="scan'208";a="89804225" Received: from black.fi.intel.com ([10.237.72.28]) by fmviesa001.fm.intel.com with ESMTP; 14 Aug 2024 05:55:15 -0700 Received: by black.fi.intel.com (Postfix, from userid 1003) id DB69217F; Wed, 14 Aug 2024 15:55:13 +0300 (EEST) From: Andy Shevchenko To: Andy Shevchenko , linux-clk@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Cc: Michael Turquette , Stephen Boyd , Nobuhiro Iwamatsu Subject: [PATCH v2 1/2] clk: mmp: Switch to use kmemdup_array() Date: Wed, 14 Aug 2024 15:54:07 +0300 Message-ID: <20240814125513.2637955-2-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.43.0.rc1.1336.g36b5255a03ac In-Reply-To: <20240814125513.2637955-1-andriy.shevchenko@linux.intel.com> References: <20240814125513.2637955-1-andriy.shevchenko@linux.intel.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240814_055520_053675_90234C48 X-CRM114-Status: GOOD ( 10.97 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Let the kmemdup_array() take care about multiplication and possible overflows. Signed-off-by: Andy Shevchenko --- drivers/clk/mmp/clk-mix.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/drivers/clk/mmp/clk-mix.c b/drivers/clk/mmp/clk-mix.c index 454d131f475e..07ac9e6937e5 100644 --- a/drivers/clk/mmp/clk-mix.c +++ b/drivers/clk/mmp/clk-mix.c @@ -447,7 +447,6 @@ struct clk *mmp_clk_register_mix(struct device *dev, struct mmp_clk_mix *mix; struct clk *clk; struct clk_init_data init; - size_t table_bytes; mix = kzalloc(sizeof(*mix), GFP_KERNEL); if (!mix) @@ -461,8 +460,8 @@ struct clk *mmp_clk_register_mix(struct device *dev, memcpy(&mix->reg_info, &config->reg_info, sizeof(config->reg_info)); if (config->table) { - table_bytes = sizeof(*config->table) * config->table_size; - mix->table = kmemdup(config->table, table_bytes, GFP_KERNEL); + mix->table = kmemdup_array(config->table, config->table_size, + sizeof(*mix->table), GFP_KERNEL); if (!mix->table) goto free_mix; @@ -470,9 +469,8 @@ struct clk *mmp_clk_register_mix(struct device *dev, } if (config->mux_table) { - table_bytes = sizeof(u32) * num_parents; - mix->mux_table = kmemdup(config->mux_table, table_bytes, - GFP_KERNEL); + mix->mux_table = kmemdup_array(config->mux_table, num_parents, + sizeof(*mix->mux_table), GFP_KERNEL); if (!mix->mux_table) { kfree(mix->table); goto free_mix; From patchwork Wed Aug 14 12:54:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 13763465 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 20197C52D7B for ; Wed, 14 Aug 2024 12:56:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=qcrhu++vGFdPq/ni6Ucoj0gqK+S1YcEKhN4NGqMkP9s=; b=P254yiZvFqnZ47DW3u+Uhfjib+ JuXiaJp/wFjHz/4D1aUpjNSAHROQEvnqc6XFsblcrLGEuhBj4dFWSxpxTUystes2SRNW5fYjZ2NPI ojDDVg8Wnndm0hx9jNZEk5w8iHVsS8E9N8udG4G6i9vVt+mYTaeh/urz8IPvMGWk1MONZR8DtLqCu 22lMAnnnsL3Avf3Ja81O09TPRlNG3UHbQRANjO29mUZv2JsHSpUyQLgleR+jGhDKG7YC99/mVBaWR rey8OxQOVSXa8HmpFJ+ZNXLUdtj8Slc3knZ/K7Paey2yAVSHtJrkqasnASU5QrQDEofDpQOn5Ee0+ NH5vSj2A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1seDYK-000000070rh-0z7e; Wed, 14 Aug 2024 12:56:36 +0000 Received: from mgamail.intel.com ([192.198.163.15]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1seDX5-000000070Tw-2Ry5 for linux-arm-kernel@lists.infradead.org; Wed, 14 Aug 2024 12:55:21 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1723640120; x=1755176120; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=APdEsDB4uRUfTA63O96E6T6zEAl1Dq01I03zQVCsNlk=; b=TFxbwEQjj5zsR/JBEs/rm0auWQgGnVUQRWCE7Y22XjOrnYqksz5v1+wr o6y+zdXRp/hCCdnwiDesHh6hDJodmj4ciMyiarMUFHw8t4Ozg7roy9wwt vhr61s/h+6D1YwRWweVcP11WuCyWVnGnXKh0MUn7K0oOUtFSrmzpz2hwj z1Y/r39k4mbL8fVwQdKE1We1dfkJrT7RNwJR2psFfqB5CGX4W1kmWSwGE GvEubVOPdoERPLIJOiJCUg0Lb7XsOiASLIfhKXpYCZba7VERyemkJkMfh exPCQ2FDMWEy38fPRWcjQzA6L1g52evYEWQ+rTFD/K1xw7Mo2979SAXap g==; X-CSE-ConnectionGUID: F4wMWhQlQpSLhCZLiSH1Dg== X-CSE-MsgGUID: 2xVdbFqjSNSE2HAjPM67ig== X-IronPort-AV: E=McAfee;i="6700,10204,11164"; a="22010672" X-IronPort-AV: E=Sophos;i="6.10,145,1719903600"; d="scan'208";a="22010672" Received: from fmviesa001.fm.intel.com ([10.60.135.141]) by fmvoesa109.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Aug 2024 05:55:17 -0700 X-CSE-ConnectionGUID: tYGueyiRSOmWo/oRDpCZoQ== X-CSE-MsgGUID: WpwGN25MQM+gY6nt7vThPw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.10,145,1719903600"; d="scan'208";a="89804224" Received: from black.fi.intel.com ([10.237.72.28]) by fmviesa001.fm.intel.com with ESMTP; 14 Aug 2024 05:55:15 -0700 Received: by black.fi.intel.com (Postfix, from userid 1003) id E0C012FB; Wed, 14 Aug 2024 15:55:13 +0300 (EEST) From: Andy Shevchenko To: Andy Shevchenko , linux-clk@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Cc: Michael Turquette , Stephen Boyd , Nobuhiro Iwamatsu Subject: [PATCH v2 2/2] clk: visconti: Switch to use kmemdup_array() Date: Wed, 14 Aug 2024 15:54:08 +0300 Message-ID: <20240814125513.2637955-3-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.43.0.rc1.1336.g36b5255a03ac In-Reply-To: <20240814125513.2637955-1-andriy.shevchenko@linux.intel.com> References: <20240814125513.2637955-1-andriy.shevchenko@linux.intel.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240814_055519_765210_DD33802A X-CRM114-Status: GOOD ( 11.02 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Let the kmemdup_array() take care about multiplication and possible overflows. Signed-off-by: Andy Shevchenko --- drivers/clk/visconti/pll.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/clk/visconti/pll.c b/drivers/clk/visconti/pll.c index e9cd80e085dc..3f929cf8dd2f 100644 --- a/drivers/clk/visconti/pll.c +++ b/drivers/clk/visconti/pll.c @@ -262,9 +262,9 @@ static struct clk_hw *visconti_register_pll(struct visconti_pll_provider *ctx, for (len = 0; rate_table[len].rate != 0; ) len++; pll->rate_count = len; - pll->rate_table = kmemdup(rate_table, - pll->rate_count * sizeof(struct visconti_pll_rate_table), - GFP_KERNEL); + pll->rate_table = kmemdup_array(rate_table, + pll->rate_count, sizeof(*pll->rate_table), + GFP_KERNEL); WARN(!pll->rate_table, "%s: could not allocate rate table for %s\n", __func__, name); init.ops = &visconti_pll_ops;