Received: by 2002:a05:6358:a55:b0:ec:fcf4:3ecf with SMTP id 21csp6595745rwb; Wed, 18 Jan 2023 07:09:03 -0800 (PST) X-Google-Smtp-Source: AMrXdXtgD+ylmwYzGamAxuQnq4wfSCUZsyafsMkQ1dRNx5mvF7itMeEHpMWocKWU3IhUK1INKFPp X-Received: by 2002:a17:906:40d:b0:84d:3623:bf5e with SMTP id d13-20020a170906040d00b0084d3623bf5emr6194356eja.24.1674054542702; Wed, 18 Jan 2023 07:09:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674054542; cv=none; d=google.com; s=arc-20160816; b=AIC/oM92450NBpPbu1h49WxRO2BdmIP0+u0WFCNNiu+KPdopCvX9KWwhTYtGS90r2K fiZJ4WfPbvPeVt3pKhXNHwFjvd45LWr/8HT+DczldoD8dBP6ibNajG5A9HgHmiLwXHEr 9s2dRPP23Rlihhbkp45Aq6ToCk8AT6mxnAQigceaP9F7xerfJ3hSbmdLTU7kbOzHT1iy XBFbht09NY+orQzZPhEyBioBOPSGbtbVx8loyeGtLycRz4sY7jC4EPzlnsSdkCUOUp0I iHbAANxDmhgecYt54dVSIpTis0XvlMjjHpUE/ABbcQWRrwOOPfK30cpsrR5jgdjTnYh0 JO2Q== 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 :dkim-signature; bh=0DLJ2VsSBzsfYtINuPT2AemVacGyEYeBlxVSd/k67oo=; b=jGWn2d9wkuBIsolVhqdZngY5wnooLxJNM2AsBOzyL19sbvCYXJAILVgR50dhIRNlcp A38Giw9G1XzGaJsWWhby8rbQZYS4qHt8Kd8K5qXy9sdN5aLLNdk3BYUePHuY//2xtRU1 2Avkt1szqweVUj5s+swjVOsknNUMXUc49LDltcBZdR5k584EX6H9/7/8c0+lBhOJhawA laildwpUbcU9cZ6VIpWaiYWDT0wbF5R0mguCU1di5MxB7ZkFB1sRRcnp+441bbE7yAgZ 3vLvtrNkLDY7px0aPc9mLKpDB7V99WiF2coKskqquvRWgQ7QyF0Hr30Nmk2rNdYr4Grc 5YPg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@pappasbrent.com header.s=default header.b=nDX1ABUr; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id hd16-20020a170907969000b007c122a9ba98si35534815ejc.685.2023.01.18.07.08.50; Wed, 18 Jan 2023 07:09:02 -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; dkim=fail header.i=@pappasbrent.com header.s=default header.b=nDX1ABUr; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231373AbjAROuc (ORCPT + 45 others); Wed, 18 Jan 2023 09:50:32 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50290 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231681AbjAROuE (ORCPT ); Wed, 18 Jan 2023 09:50:04 -0500 Received: from h5.fbrelay.privateemail.com (h5.fbrelay.privateemail.com [162.0.218.228]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E679F86B3; Wed, 18 Jan 2023 06:42:48 -0800 (PST) Received: from MTA-07-4.privateemail.com (unknown [198.54.122.141]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by h5.fbrelay.privateemail.com (Postfix) with ESMTPS id D3C3B60730; Wed, 18 Jan 2023 14:42:46 +0000 (UTC) Received: from mta-07.privateemail.com (localhost [127.0.0.1]) by mta-07.privateemail.com (Postfix) with ESMTP id 404D41801119; Wed, 18 Jan 2023 09:42:40 -0500 (EST) Received: from bpappas-XPS-13-9310.ucf.edu (050-088-208-136.res.spectrum.com [50.88.208.136]) by mta-07.privateemail.com (Postfix) with ESMTPA id CE0201801126; Wed, 18 Jan 2023 09:42:28 -0500 (EST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=pappasbrent.com; s=default; t=1674052960; bh=FqDHCHvsB52HFi8bEmC/gtO/khX/839t5pQ/ZUuPeVI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=nDX1ABUr4GRiT7rKx/G8R8mJ4M0QNyUby6oxCSCAIF8TZ59UJ4aBGuazu6aDiVKTj 7JQ6ivf3fjLUcnHsVKDN2YOfFILVvLrXNTIJOjb6WtC57SZe5GViJxANiGVt2N46bk 3V8m/8olN4+7A9jBysabb5U7Fq/gVWg7s49keBD3yONjEJE0LLD3WGtYUqFvxhEsT9 mkqi690Mb2asL7jo6rnP8wT/oPcLK8HmEIVxy61RwGeJ70jbCMs7H+gxNyhmMJX+YY TZHyRzNnsP5Hyf002ikc9joVMOGp1YQZIZP1z0jfmYdRtTmOnChkjCkT8p4hLb4ztl YByZgGmFc6qrQ== From: Brent Pappas To: andy.shevchenko@gmail.com Cc: ailus@linux.intel.com, bpappas@pappasbrent.com, error27@gmail.com, gregkh@linuxfoundation.org, hdegoede@redhat.com, linux-kernel@vger.kernel.org, linux-media@vger.kernel.org, linux-staging@lists.linux.dev, mchehab@kernel.org Subject: [PATCH v4] media: atomisp: pci: Replace bytes macros with functions Date: Wed, 18 Jan 2023 09:42:26 -0500 Message-Id: <20230118144226.13127-1-bpappas@pappasbrent.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Virus-Scanned: ClamAV using ClamSMTP X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS, SPF_PASS 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 Replace the function-like macros FPNTBL_BYTES(), SCTBL_BYTES(), and MORPH_PLANE_BYTES() with functions to comply with Linux coding style standards. Replace multiplication with calls to functions/macros from overflow.h to prevent accidental arithmetic overflow. Signed-off-by: Brent Pappas --- Changelog: V1 -> V2: Use size_mul() to perform size_t multiplication without risk of overflow. Remove the inline keyword from function definitions. V2 -> V3: Add commit message. V3 -> V4: Use array_size() and array3_size() for multiplication. .../staging/media/atomisp/pci/sh_css_params.c | 38 +++++++++++-------- 1 file changed, 23 insertions(+), 15 deletions(-) diff --git a/drivers/staging/media/atomisp/pci/sh_css_params.c b/drivers/staging/media/atomisp/pci/sh_css_params.c index f08564f58242..7e111df5c09d 100644 --- a/drivers/staging/media/atomisp/pci/sh_css_params.c +++ b/drivers/staging/media/atomisp/pci/sh_css_params.c @@ -98,17 +98,27 @@ #include "sh_css_frac.h" #include "ia_css_bufq.h" -#define FPNTBL_BYTES(binary) \ - (sizeof(char) * (binary)->in_frame_info.res.height * \ - (binary)->in_frame_info.padded_width) +static size_t fpntbl_bytes(const struct ia_css_binary *binary) +{ + return array3_size(sizeof(char), + binary->in_frame_info.res.height, + binary->in_frame_info.padded_width); +} -#define SCTBL_BYTES(binary) \ - (sizeof(unsigned short) * (binary)->sctbl_height * \ - (binary)->sctbl_aligned_width_per_color * IA_CSS_SC_NUM_COLORS) +static size_t sctbl_bytes(const struct ia_css_binary *binary) +{ + return array_size(sizeof(unsigned short), + array3_size(binary->sctbl_height, + binary->sctbl_aligned_width_per_color, + IA_CSS_SC_NUM_COLORS)); +} -#define MORPH_PLANE_BYTES(binary) \ - (SH_CSS_MORPH_TABLE_ELEM_BYTES * (binary)->morph_tbl_aligned_width * \ - (binary)->morph_tbl_height) +static size_t morph_plane_bytes(const struct ia_css_binary *binary) +{ + return array3_size(SH_CSS_MORPH_TABLE_ELEM_BYTES, + binary->morph_tbl_aligned_width, + binary->morph_tbl_height); +} /* We keep a second copy of the ptr struct for the SP to access. Again, this would not be necessary on the chip. */ @@ -3279,7 +3289,7 @@ sh_css_params_write_to_ddr_internal( if (binary->info->sp.enable.fpnr) { buff_realloced = reallocate_buffer(&ddr_map->fpn_tbl, &ddr_map_size->fpn_tbl, - (size_t)(FPNTBL_BYTES(binary)), + fpntbl_bytes(binary), params->config_changed[IA_CSS_FPN_ID], &err); if (err) { @@ -3304,7 +3314,7 @@ sh_css_params_write_to_ddr_internal( buff_realloced = reallocate_buffer(&ddr_map->sc_tbl, &ddr_map_size->sc_tbl, - SCTBL_BYTES(binary), + sctbl_bytes(binary), params->sc_table_changed, &err); if (err) { @@ -3538,8 +3548,7 @@ sh_css_params_write_to_ddr_internal( buff_realloced |= reallocate_buffer(virt_addr_tetra_x[i], virt_size_tetra_x[i], - (size_t) - (MORPH_PLANE_BYTES(binary)), + morph_plane_bytes(binary), params->morph_table_changed, &err); if (err) { @@ -3549,8 +3558,7 @@ sh_css_params_write_to_ddr_internal( buff_realloced |= reallocate_buffer(virt_addr_tetra_y[i], virt_size_tetra_y[i], - (size_t) - (MORPH_PLANE_BYTES(binary)), + morph_plane_bytes(binary), params->morph_table_changed, &err); if (err) { -- 2.34.1