Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp5547895rwr; Tue, 9 May 2023 03:07:49 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4goD3A65KiGJqmRlD2bTE+HewXsOt7WpzGHhxyL9Ohi5dPo/NzrHcXp8JWiO2w1sA15jnD X-Received: by 2002:a17:90b:691:b0:24e:4231:ec67 with SMTP id m17-20020a17090b069100b0024e4231ec67mr21118580pjz.9.1683626869099; Tue, 09 May 2023 03:07:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683626869; cv=none; d=google.com; s=arc-20160816; b=h7dE1J9t0LfyXr3XccG5xejmg58E0pIttyIMJmtAZgkgiuxQSJZmThLlRJQUchEIPl cn+m5AaBa3CbV8+TQnqRJ/jblKng5b9N0nnerrj5grUa23dMu/esD4q/NlqnYocQDFvH /nMk6Tc2jjKBcQv8EKaesdea/1mXlpNxZ6uZVgG1powQbKgXxll0Zg0Plovh5L/Dc1/c 7GOvp/s5+/fHqH4AndAYVq3n9YsFcHQ1jz9uZ/ds5h5CW6TE1AdLknB+nb+Nsdq/T0JL BNU8FX33Z4dSk94kC5nbuCl4jQ3iFfw/dqP8ww1lRgksQs/pb50HzO3Tqw58OPhBM6sP IBVQ== 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=h9wkM8yPGkaGonMyYhLzRDxl+xgUTZYDn/Dnurhy5Wk=; b=Dv0rrM84eynGyHpwZKS8tY3E7s/rErUfNFdEHspXxJgie5Jv1xBP1xsP1DcJMiYAae xl2Vff9Ae9TdbL4stiO5Zx2uhk5nypqc/ZxknGN0/vRQ5Xzu3XaxGmlgl7NWJq+U1WN3 Cv2WeMQWehhtn9mqivfEoPJPfAaiHt6wg+YAdENUj4C9aApfkxGDfjsg3NdsGemTTkgU hZpPtfWEqrnvS05KwuitngluPnMYefY30XzYYE+kTofaWZrfyi0ZUdPLgiu62NwvllbS n5HV6CphpNGjgWIzs89JsjT/qjdOlVdYsyTdCzSZSdnZEftdrU/BkU2JEP4C4uBo4QRH zDzw== 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id e22-20020a17090a9a9600b0024df5961ddasi21139978pjp.93.2023.05.09.03.07.33; Tue, 09 May 2023 03:07:49 -0700 (PDT) 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 S235074AbjEIJun (ORCPT + 99 others); Tue, 9 May 2023 05:50:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60670 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234772AbjEIJuK (ORCPT ); Tue, 9 May 2023 05:50:10 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id B4743D9; Tue, 9 May 2023 02:50:09 -0700 (PDT) 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 DA7491063; Tue, 9 May 2023 02:50:53 -0700 (PDT) Received: from e127643.arm.com (unknown [10.57.83.64]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id D5FCD3F67D; Tue, 9 May 2023 02:50:05 -0700 (PDT) From: James Clark To: linux-kernel@vger.kernel.org, gregkh@linuxfoundation.org Cc: linux@roeck-us.net, michal.simek@amd.com, Jonathan.Cameron@huawei.com, James Clark , Jonathan Corbet , Jean Delvare , Anand Ashok Dumbre , Jonathan Cameron , Lars-Peter Clausen , Andy Gross , Bjorn Andersson , Konrad Dybcio , 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 v4 3/4] iio: adc: Use devm_krealloc_array Date: Tue, 9 May 2023 10:49:40 +0100 Message-Id: <20230509094942.396150-4-james.clark@arm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230509094942.396150-1-james.clark@arm.com> References: <20230509094942.396150-1-james.clark@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE 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 Now that it exists, use it instead of doing the multiplication and checking for overflow manually. Reviewed-by: Jonathan Cameron 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..dba73300f894 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; -- 2.34.1