From patchwork Mon Mar 6 15:27:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Clark X-Patchwork-Id: 64778 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp1907058wrd; Mon, 6 Mar 2023 07:33:49 -0800 (PST) X-Google-Smtp-Source: AK7set+bM560j1X3MfgAnM4CTUV0/VMwMOf8eVxMdxpLOz8+6lZpWvLppNkmSjeQp1jxi5aqvTqW X-Received: by 2002:a05:6a20:12cd:b0:cd:40b4:bc75 with SMTP id v13-20020a056a2012cd00b000cd40b4bc75mr13115753pzg.48.1678116829169; Mon, 06 Mar 2023 07:33:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1678116829; cv=none; d=google.com; s=arc-20160816; b=As/Jq55eERdGpmq6S7FbHggEvqrZLEj2ThDIItjrSPEl8FETjXj3xZ/CdORIL5uRaw 6nUReoTRs0F4NLj07d2pS+F3iMYP4Q4S5xFKi0m9YPNrlDovHsYq3x4x80L3gLXKK4vS YoeOuH45rxC+a5MpPHWEmlGtvj+11kPIn2GR7okpLvZOB06qfTxHm7WtBXimlbPJ2iUd aYhlpRafFPP2GxSKHYOb6yWT2XppP5wjYGR7o+YaFci2GxDYZDFPIdOkXBX7f103e0e1 9ZlSnHA85om+qzM7tTVwICX46TjwLW59uQXsA+O7DxyITCvEwHUo/C8Qt4UFEf6l2kUu KUXw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=bObyX/9ta0F98Bi05gDbVLq/2EMQ01dhumYM8iQPKgM=; b=eWbK2EaNBH3uq6+0yh6+SrjxAJuPPVI/ZXZca/oTm/9YZg0ElabUlguboKaNvQnoip dwqjney0hwHug0xSaNEkSJ+DBAq41uY3dDiOUvuZoZY6F1A7pnyJFAEy3Fv7dt64mx14 ROdwT6yjDS35TO6ptn3F9nOuOzvmczbJglIa3kUTez/DtN1d7dMbzNpk/Nt3rGGF9YDJ sMU0ND+1pXjwv8cLaMpLDzA1mf6tMORRDKzgynu2/A7Pw4p8YW+Tun3gkAVA8LUGyI4b 7fZTVS3LAGeV1kczyRf1LN5z1UDwAKzUSG03I5zjwqAeHFU7YEDHUTQ0i7gvpbUxr+Kk XqFA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h9-20020a63df49000000b004fb9d7d19b4si9956006pgj.726.2023.03.06.07.33.36; Mon, 06 Mar 2023 07:33:49 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229973AbjCFP15 (ORCPT + 99 others); Mon, 6 Mar 2023 10:27:57 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48056 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231284AbjCFP1s (ORCPT ); Mon, 6 Mar 2023 10:27:48 -0500 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 77F50311E6; Mon, 6 Mar 2023 07:27:40 -0800 (PST) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 8B6B213D5; Mon, 6 Mar 2023 07:28:23 -0800 (PST) Received: from e127643.broadband (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 90B593F71A; Mon, 6 Mar 2023 07:27:37 -0800 (PST) From: James Clark To: linux-kernel@vger.kernel.org Cc: James Clark , Jonathan Corbet , Guenter Roeck , Jean Delvare , Anand Ashok Dumbre , Jonathan Cameron , Lars-Peter Clausen , Michal Simek , Andy Gross , Bjorn Andersson , Konrad Dybcio , Greg Kroah-Hartman , Jiri Slaby , linux-doc@vger.kernel.org, linux-hwmon@vger.kernel.org, linux-iio@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-arm-msm@vger.kernel.org, linux-serial@vger.kernel.org Subject: [PATCH 1/4] devres: Provide krealloc_array Date: Mon, 6 Mar 2023 15:27:20 +0000 Message-Id: <20230306152723.3090195-2-james.clark@arm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230306152723.3090195-1-james.clark@arm.com> References: <20230306152723.3090195-1-james.clark@arm.com> MIME-Version: 1.0 X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1759633031825614640?= X-GMAIL-MSGID: =?utf-8?q?1759633031825614640?= There is no krealloc_array equivalent in devres. Users would have to do their own multiplication overflow check so provide one. Signed-off-by: James Clark --- Documentation/driver-api/driver-model/devres.rst | 1 + include/linux/device.h | 10 ++++++++++ 2 files changed, 11 insertions(+) diff --git a/Documentation/driver-api/driver-model/devres.rst b/Documentation/driver-api/driver-model/devres.rst index 4249eb4239e0..8be086b3f829 100644 --- a/Documentation/driver-api/driver-model/devres.rst +++ b/Documentation/driver-api/driver-model/devres.rst @@ -364,6 +364,7 @@ MEM devm_kmalloc_array() devm_kmemdup() devm_krealloc() + devm_krealloc_array() devm_kstrdup() devm_kstrdup_const() devm_kvasprintf() diff --git a/include/linux/device.h b/include/linux/device.h index 1508e637bb26..0dd5956c8516 100644 --- a/include/linux/device.h +++ b/include/linux/device.h @@ -223,6 +223,16 @@ static inline void *devm_kcalloc(struct device *dev, { return devm_kmalloc_array(dev, n, size, flags | __GFP_ZERO); } +static inline __realloc_size(3, 4) void * __must_check +devm_krealloc_array(struct device *dev, void *p, size_t new_n, size_t new_size, gfp_t flags) +{ + size_t bytes; + + if (unlikely(check_mul_overflow(new_n, new_size, &bytes))) + return NULL; + return devm_krealloc(dev, p, bytes, flags); +} + void devm_kfree(struct device *dev, const void *p); char *devm_kstrdup(struct device *dev, const char *s, gfp_t gfp) __malloc; const char *devm_kstrdup_const(struct device *dev, const char *s, gfp_t gfp); From patchwork Mon Mar 6 15:27:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Clark X-Patchwork-Id: 64785 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp1913391wrd; Mon, 6 Mar 2023 07:46:39 -0800 (PST) X-Google-Smtp-Source: AK7set+SVdoEf9r5BAHllHJAe+1jR+4Z/Jk6jKFlAMzbD0gKA5SgWgy8V5MFru6IFFA+fJpS25BB X-Received: by 2002:a05:6a21:328d:b0:cc:6b15:2bd6 with SMTP id yt13-20020a056a21328d00b000cc6b152bd6mr13300155pzb.25.1678117598806; Mon, 06 Mar 2023 07:46:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1678117598; cv=none; d=google.com; s=arc-20160816; b=JhVDVrCzqMk/wg9tiW86zSuchj/0qH7flB4jF6Tk5LU+XTXwL4yLUquyzNDedrsYiX fEFFV2Y8D7iY6ub7NOf44Kwc9YEpCFtZ2quTm0gAUOfn8Hpc985gWuDVDtodB3H6V3W+ eUJn8X6nPx6oK6pcF81UDa90L4iUHYFR6BWOBWDRHUCblAYRMQ+CyjX9DcE2Ek/OL3Gp DPpkULlpCufM6kA97SO6cZFGBVVqCDxlE+PsrYK0hNWpRhxR8k/o8GM43w6LTEVWUZwK 43pQ8WirP330/wMUw6QDrhtb0r9vJZA36gKdepiXsW3dFD7W6ZxeQGKx1v0ee3G1mjXw sc5w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=tl64g2Yvr/5NxeDTT7oQzWtjoLuwFLPOYB2THgpZzeI=; b=L0KiDYwqbUoqsqlrgZzk7Tuu9Pfetf7KVmy62LmSwUgpOEoRcamJvnxlZIq/ux8rlK izNAilEXOtBHHu83f029PffzWE3B6mk3tj4OC4nJaqdOewmrzFDu4qMiZ1jqFHglz2Kn U1N0NhYCEpNaa2pup7MgJkRs8MpH1f6kw8aHGLiG97Vn2jK1w5EYjZ72f5T6DBR7/MIw mmyoUim5JbQdweDGeeFw6Ws9aUKwmZZHgd2j9bNqGvd2jjSrc9+JoWNud6lqMnakQDNq 73gZ2x06qcLUw6ByEyNwVNzRu5nprrJ1KLJYp8bvBDXog0rlffl4xNxn6thlbYOqT0ow kuhA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q134-20020a632a8c000000b004fbd746d0f1si9245384pgq.564.2023.03.06.07.46.25; Mon, 06 Mar 2023 07:46:38 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229999AbjCFP2F (ORCPT + 99 others); Mon, 6 Mar 2023 10:28:05 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48062 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229846AbjCFP1w (ORCPT ); Mon, 6 Mar 2023 10:27:52 -0500 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id C48F3301A8; Mon, 6 Mar 2023 07:27:43 -0800 (PST) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id E68521424; Mon, 6 Mar 2023 07:28:26 -0800 (PST) Received: from e127643.broadband (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id E3A703F71A; Mon, 6 Mar 2023 07:27:40 -0800 (PST) From: James Clark To: linux-kernel@vger.kernel.org Cc: James Clark , Jonathan Corbet , Guenter Roeck , Jean Delvare , Anand Ashok Dumbre , Jonathan Cameron , Lars-Peter Clausen , Michal Simek , Andy Gross , Bjorn Andersson , Konrad Dybcio , Greg Kroah-Hartman , Jiri Slaby , linux-doc@vger.kernel.org, linux-hwmon@vger.kernel.org, linux-iio@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-arm-msm@vger.kernel.org, linux-serial@vger.kernel.org Subject: [PATCH 2/4] hwmon: pmbus: Use devm_krealloc_array Date: Mon, 6 Mar 2023 15:27:21 +0000 Message-Id: <20230306152723.3090195-3-james.clark@arm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230306152723.3090195-1-james.clark@arm.com> References: <20230306152723.3090195-1-james.clark@arm.com> MIME-Version: 1.0 X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1759633839560124691?= X-GMAIL-MSGID: =?utf-8?q?1759633839560124691?= Now that it exists, use it instead of doing the multiplication manually. Signed-off-by: James Clark Acked-by: Guenter Roeck --- drivers/hwmon/pmbus/pmbus_core.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/hwmon/pmbus/pmbus_core.c b/drivers/hwmon/pmbus/pmbus_core.c index 95e95783972a..e7bee25a3706 100644 --- a/drivers/hwmon/pmbus/pmbus_core.c +++ b/drivers/hwmon/pmbus/pmbus_core.c @@ -1190,9 +1190,9 @@ static int pmbus_add_attribute(struct pmbus_data *data, struct attribute *attr) { if (data->num_attributes >= data->max_attributes - 1) { int new_max_attrs = data->max_attributes + PMBUS_ATTR_ALLOC_SIZE; - void *new_attrs = devm_krealloc(data->dev, data->group.attrs, - new_max_attrs * sizeof(void *), - GFP_KERNEL); + void *new_attrs = devm_krealloc_array(data->dev, data->group.attrs, + new_max_attrs, sizeof(void *), + GFP_KERNEL); if (!new_attrs) return -ENOMEM; data->group.attrs = new_attrs; From patchwork Mon Mar 6 15:27:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Clark X-Patchwork-Id: 64809 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp1922169wrd; Mon, 6 Mar 2023 08:02:49 -0800 (PST) X-Google-Smtp-Source: AK7set/honFbKBPJUH2wreefGz8g0OaeyzNHXTAwlO7eYEvSFycv3Y9JhdE+9CM4RZZvpZ5M8AlC X-Received: by 2002:aa7:d04e:0:b0:4ad:7c7c:a70d with SMTP id n14-20020aa7d04e000000b004ad7c7ca70dmr10737207edo.19.1678118569524; Mon, 06 Mar 2023 08:02:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1678118569; cv=none; d=google.com; s=arc-20160816; b=oqireZ/rjEXb0yp6i5MB8o7+XDSeJCsifuoZDAdjwMfD8TFj6ssCRk3suYTjnS+kpl fizVJ7D18DKAsEy5JEKm0I+Du1z3L6N+yaT5J4UxzGAVkvPsyclcrZN5zc9dMn3S94Bp x2jDezH8TshuO3VDCbhUjn+5mkxFC1GcejqkqTHNHcwiVJh+FgmWGqTAODs11Hl+tYUZ ZzZpfNzwjBvYMAJyQg/yp2STojc+j7UJtCAINqd4wBhsfzhZHh+w9m85xjlb8ojXwB4r j6pmRSxNGkEErKKyIVGWlSum3usZILJuzf4isRBgAb6NtkDKqrGLd1pcjQYZ/PNMR4wS /P6w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=zNgEEFoRppYcqkB28yb8iRybzBzNOpdXLdLTU54hPL4=; b=PVRbhukl8McXUMn3n43XXDyiergdxRpKihuuMIS/L7o8nJhSC4kFg5uuqk8CyCpFlK OLaaliedyxXbsE2EaLSXdQrS3ggkUJ/s3nyCnvcDWb7jJ1IFSwXHEh4w/D0rdFyz7Yq9 LcvZv+yRnaOuxlBPPiwYlHGFy5Rgt7cqMq7cmBLsNpgp7qlznhh+Fk2KEZx5C28Gj7JL VTGntRU0AgK1Y0exU+oA9Dw8JHsUokIL/uVf+twVXwdofMeyi3BonaQHCkQu2ow8698O TFbaEZWo9xizJSFpmAMN+/NOtwapbpBkbfYPV6nO4MCX10mOH7khjpIm+i/ux+14l2GY eqGw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id rh14-20020a17090720ee00b009079470b7b1si8992341ejb.391.2023.03.06.08.02.20; Mon, 06 Mar 2023 08:02:49 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231283AbjCFP2J (ORCPT + 99 others); Mon, 6 Mar 2023 10:28:09 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47970 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231263AbjCFP16 (ORCPT ); Mon, 6 Mar 2023 10:27:58 -0500 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 292C631E19; Mon, 6 Mar 2023 07:27:47 -0800 (PST) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 49D8E143D; Mon, 6 Mar 2023 07:28:30 -0800 (PST) Received: from e127643.broadband (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 506183F71A; Mon, 6 Mar 2023 07:27:44 -0800 (PST) From: James Clark To: linux-kernel@vger.kernel.org Cc: James Clark , Jonathan Corbet , Guenter Roeck , Jean Delvare , Anand Ashok Dumbre , Jonathan Cameron , Lars-Peter Clausen , Michal Simek , Andy Gross , Bjorn Andersson , Konrad Dybcio , Greg Kroah-Hartman , Jiri Slaby , linux-doc@vger.kernel.org, linux-hwmon@vger.kernel.org, linux-iio@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-arm-msm@vger.kernel.org, linux-serial@vger.kernel.org Subject: [PATCH 3/4] iio: adc: Use devm_krealloc_array Date: Mon, 6 Mar 2023 15:27:22 +0000 Message-Id: <20230306152723.3090195-4-james.clark@arm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230306152723.3090195-1-james.clark@arm.com> References: <20230306152723.3090195-1-james.clark@arm.com> MIME-Version: 1.0 X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1759634857242756696?= X-GMAIL-MSGID: =?utf-8?q?1759634857242756696?= Now that it exists, use it instead of doing the multiplication and checking for overflow manually. Signed-off-by: James Clark --- drivers/iio/adc/xilinx-ams.c | 9 +++------ drivers/iio/adc/xilinx-xadc-core.c | 17 +++++++---------- 2 files changed, 10 insertions(+), 16 deletions(-) diff --git a/drivers/iio/adc/xilinx-ams.c b/drivers/iio/adc/xilinx-ams.c index 34cf336b3490..f0b71a1220e0 100644 --- a/drivers/iio/adc/xilinx-ams.c +++ b/drivers/iio/adc/xilinx-ams.c @@ -1263,7 +1263,7 @@ static int ams_parse_firmware(struct iio_dev *indio_dev) struct device *dev = indio_dev->dev.parent; struct fwnode_handle *child = NULL; struct fwnode_handle *fwnode = dev_fwnode(dev); - size_t ams_size, dev_size; + size_t ams_size; int ret, ch_cnt = 0, i, rising_off, falling_off; unsigned int num_channels = 0; @@ -1320,11 +1320,8 @@ static int ams_parse_firmware(struct iio_dev *indio_dev) } } - dev_size = array_size(sizeof(*dev_channels), num_channels); - if (dev_size == SIZE_MAX) - return -ENOMEM; - - dev_channels = devm_krealloc(dev, ams_channels, dev_size, GFP_KERNEL); + dev_channels = devm_krealloc_array(dev, ams_channels, num_channels, + sizeof(*dev_channels), GFP_KERNEL); if (!dev_channels) return -ENOMEM; diff --git a/drivers/iio/adc/xilinx-xadc-core.c b/drivers/iio/adc/xilinx-xadc-core.c index 292f2892d223..287df3bb951e 100644 --- a/drivers/iio/adc/xilinx-xadc-core.c +++ b/drivers/iio/adc/xilinx-xadc-core.c @@ -613,20 +613,17 @@ static int xadc_update_scan_mode(struct iio_dev *indio_dev, const unsigned long *mask) { struct xadc *xadc = iio_priv(indio_dev); - size_t new_size, n; + size_t n; void *data; n = bitmap_weight(mask, indio_dev->masklength); - if (check_mul_overflow(n, sizeof(*xadc->data), &new_size)) - return -ENOMEM; - - data = devm_krealloc(indio_dev->dev.parent, xadc->data, - new_size, GFP_KERNEL); + data = devm_krealloc_array(indio_dev->dev.parent, xadc->data, + n, sizeof(*xadc->data), GFP_KERNEL); if (!data) return -ENOMEM; - memset(data, 0, new_size); + memset(data, 0, n*sizeof(*xadc->data)); xadc->data = data; return 0; @@ -1281,9 +1278,9 @@ static int xadc_parse_dt(struct iio_dev *indio_dev, unsigned int *conf, int irq) } indio_dev->num_channels = num_channels; - indio_dev->channels = devm_krealloc(dev, channels, - sizeof(*channels) * num_channels, - GFP_KERNEL); + indio_dev->channels = devm_krealloc_array(dev, channels, + num_channels, sizeof(*channels), + GFP_KERNEL); /* If we can't resize the channels array, just use the original */ if (!indio_dev->channels) indio_dev->channels = channels; From patchwork Mon Mar 6 15:27:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Clark X-Patchwork-Id: 64781 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp1908037wrd; Mon, 6 Mar 2023 07:35:49 -0800 (PST) X-Google-Smtp-Source: AK7set/54II+DaO5l2zbfUQvZaj+tvb+aS2Qms6yT6+eMOD8W6koYHfsu78B6ISeOoFyzvG9gedW X-Received: by 2002:a50:ed94:0:b0:4bc:7eb9:4b2c with SMTP id h20-20020a50ed94000000b004bc7eb94b2cmr10545849edr.35.1678116949184; Mon, 06 Mar 2023 07:35:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1678116949; cv=none; d=google.com; s=arc-20160816; b=Bwvg1m6Zl/3zAOxHeWa2D6YaJ3JlCiBnwGkYgZtsPKwFA1EdYumVkTu5Y6bhVzKS7X TmKtuECaondFTr3bNv5XNlZSj14YGhzLkJPlJ67ec683qcuwAP4XHBmP2HiA5SBPxoh8 g1WVLmt1sQo9BGNIikzumj4IfNiDbhhsVpkJnJZa/EBtCc0gaP/nSaNVoeiyZ+cGSc/z XYoES8occ/R9IfB/BMzqUwWk6iUP8ZMU42d/OhHcjFGcKG9XpX5UITpeSevDDhl1fd01 tY1G/03P5x2jgGle19UsSrOJnGHwzQsEE8ooxBWlv5bx8Zr4U4EP48LrJxXfWQBVgJ58 8WQg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=VdGGhNLNS9Abb7ZRhModBwzmMvDHCJDf6wJ4Dbk1jW4=; b=LeVoNQ108QVS7pvfZNJgfQ/lXZauNwDudiI1hjrNOqkQu1gyxTQveVym7yatHgfmV8 P7CU5VkJ4Ub4dPAa5cdDlATEJajWnnO1bP5Znde5AVdnfzaP1ft7U1dB1OjLX8iXk6Wp qSPYbjh5p94fDcJiFMjBdxTdcLmfx9yY72cO/SqTTE/Kl0XhFoAqVRCYba9sn9gvK6AQ SMTM2GA7asdBnSl7PpMFkAXkeDa4MvX2pTkxd4zRNrw3I0II8GOkMU+PL5QTsltTH3pU 6pp0kaslQIGKTGgUZEfN3eP0T0cEnwt5LoAYFLZKzUjG3skUeBS6/+yjqNMQ3Nrt5oBL bRFw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id w13-20020aa7da4d000000b004cdc92cc41dsi8830284eds.142.2023.03.06.07.35.02; Mon, 06 Mar 2023 07:35:49 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231142AbjCFP2M (ORCPT + 99 others); Mon, 6 Mar 2023 10:28:12 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48858 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231285AbjCFP16 (ORCPT ); Mon, 6 Mar 2023 10:27:58 -0500 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 8285B30E9A; Mon, 6 Mar 2023 07:27:50 -0800 (PST) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id A510E12FC; Mon, 6 Mar 2023 07:28:33 -0800 (PST) Received: from e127643.broadband (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id A26133F71A; Mon, 6 Mar 2023 07:27:47 -0800 (PST) From: James Clark To: linux-kernel@vger.kernel.org Cc: James Clark , Jonathan Corbet , Guenter Roeck , Jean Delvare , Anand Ashok Dumbre , Jonathan Cameron , Lars-Peter Clausen , Michal Simek , Andy Gross , Bjorn Andersson , Konrad Dybcio , Greg Kroah-Hartman , Jiri Slaby , linux-doc@vger.kernel.org, linux-hwmon@vger.kernel.org, linux-iio@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-arm-msm@vger.kernel.org, linux-serial@vger.kernel.org Subject: [PATCH 4/4] serial: qcom_geni: Use devm_krealloc_array Date: Mon, 6 Mar 2023 15:27:23 +0000 Message-Id: <20230306152723.3090195-5-james.clark@arm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230306152723.3090195-1-james.clark@arm.com> References: <20230306152723.3090195-1-james.clark@arm.com> MIME-Version: 1.0 X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1759633158380735167?= X-GMAIL-MSGID: =?utf-8?q?1759633158380735167?= Now that it exists, use it instead of doing the multiplication manually. Signed-off-by: James Clark --- drivers/tty/serial/qcom_geni_serial.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/tty/serial/qcom_geni_serial.c b/drivers/tty/serial/qcom_geni_serial.c index d69592e5e2ec..23fc33d182ac 100644 --- a/drivers/tty/serial/qcom_geni_serial.c +++ b/drivers/tty/serial/qcom_geni_serial.c @@ -1056,9 +1056,9 @@ static int setup_fifos(struct qcom_geni_serial_port *port) (port->tx_fifo_depth * port->tx_fifo_width) / BITS_PER_BYTE; if (port->rx_buf && (old_rx_fifo_depth != port->rx_fifo_depth) && port->rx_fifo_depth) { - port->rx_buf = devm_krealloc(uport->dev, port->rx_buf, - port->rx_fifo_depth * sizeof(u32), - GFP_KERNEL); + port->rx_buf = devm_krealloc_array(uport->dev, port->rx_buf, + port->rx_fifo_depth, sizeof(u32), + GFP_KERNEL); if (!port->rx_buf) return -ENOMEM; }