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;