From mboxrd@z Thu Jan 1 00:00:00 1970 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 D7F04C74A5B for ; Sat, 18 Mar 2023 17:20:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=+5O44w1sOvQldJNSDNzGs/x12Fa5PwmqxSl2Yp5xFGc=; b=T8EaF9x64a74Vb xPS0OwcN9EFlOEnZcTwWtlkGv9B4SPxPFNIrTLun3mPSKZJkJLewwlw8eKbIYrk+Ps6KZSrNjcf6M Iq+Lu/0RI0d7kcnvnMxInOlVqQF3jDU1TBFdeNdW4UuMU5B7UdjY/pb00HfkkjXFy46ARH3TkojHJ ndJKD9bfa1APRYJyhe3cG12qSf1Gzf1+bosLHax32JXcC9Oc6KLuPcFYnRh9XMFIqYUOecnuDma4s px20wn/xC9MbkgtDV4sOWCU2LVY9WZbC9CJZMf0gkjqnkgU1zhFRzbWL9LqofE4zRXst7j5R40bei cp4UOjYsk3iJ5tjP1fEg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1pdaDQ-0053qs-1F; Sat, 18 Mar 2023 17:19:36 +0000 Received: from dfw.source.kernel.org ([139.178.84.217]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1pdaDN-0053ps-24 for linux-arm-kernel@lists.infradead.org; Sat, 18 Mar 2023 17:19:35 +0000 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 9AC4360ECC; Sat, 18 Mar 2023 17:19:30 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 74683C433D2; Sat, 18 Mar 2023 17:19:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1679159970; bh=TlLbFe2AtUWFg73uowAriW9X3Ln7J8/MMonCpaLQ7qw=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=nufTb8rQPNuar3fPQ0dMH5Hyw3V10Gjszee7hb7wLvSi4HMEM4AKOrAlbY723QHtT dgs2tVBu5NTzPy8C1UQFSgTnHumqLc2Td2TDVIRjk7+uMUh2qU4B4rs3Kilbl0/RjV hgeHeQkQpNycHhjGgtPfOgetWn1e98Y4QviFiJEE/BkAsKdz4RCincWl0TyacvNuel 0olbewnw3DCuIRvLdZadXBxLqiLt9Wl1FoFEOMcc5hswgCrg3vEXd1y3uJD6m6Mf8x JjoIO2oH1yoafj9jNqSWbCi5ridX/xu3BkB9hUKVnHLog8B/4pEHwjeTgdL7+RsWO5 mmm321tY7dzEQ== Date: Sat, 18 Mar 2023 17:34:21 +0000 From: Jonathan Cameron To: James Clark Cc: Krzysztof Kozlowski , linux-kernel@vger.kernel.org, linux@roeck-us.net, michal.simek@amd.com, Jonathan Corbet , Jean Delvare , Anand Ashok Dumbre , 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: Re: [PATCH v2 4/4] serial: qcom_geni: Use devm_krealloc_array Message-ID: <20230318173402.20a4f60d@jic23-huawei> In-Reply-To: <74d8b579-6ea8-d6f3-170f-ea13534b4565@arm.com> References: <20230309150334.216760-1-james.clark@arm.com> <20230309150334.216760-5-james.clark@arm.com> <20230311191800.74ec2b84@jic23-huawei> <74d8b579-6ea8-d6f3-170f-ea13534b4565@arm.com> X-Mailer: Claws Mail 4.1.1 (GTK 3.24.37; x86_64-pc-linux-gnu) MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230318_101933_756412_FE44BF2A X-CRM114-Status: GOOD ( 32.39 ) 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: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Fri, 17 Mar 2023 11:34:49 +0000 James Clark wrote: > On 11/03/2023 19:18, Jonathan Cameron wrote: > > On Thu, 9 Mar 2023 15:03:33 +0000 > > James Clark wrote: > > > >> Now that it exists, use it instead of doing the multiplication manually. > >> > >> Signed-off-by: James Clark > > > > Hmm. I've stared at the users of this for a bit, and it's not actually obvious > > that it's being used as an array of u32. The only typed user of this is as > > the 2nd parameter of > > tty_insert_flip_string() which is an unsigned char * > > > > I wonder if that sizeof(u32) isn't a 'correct' description of where the 4 is coming > > from even if it has the right value? Perhaps the fifo depth is just a multiple of 4? > > > > Jonathan > > > > The commit that added it (b8caf69a6946) seems to hint that something > reads from it in words. And I see this: > > /* We always configure 4 bytes per FIFO word */ > #define BYTES_PER_FIFO_WORD 4U > > Perhaps sizeof(u32) isn't as accurate of a description as using > BYTES_PER_FIFO_WORD but I'd be reluctant to make a change because I > don't really understand the implications. Agreed with your analysis. + fully understand why you don't want to change it. I'd be tempted to take the view that whilst it's allocated in 4 byte chunks because it's accessed elsewhere as a set of 1 byte entries, krealloc_array isn't appropriate and so just leave it with devm_krealloc() Risk is that a steady stream of patches will turn up 'fixing' this as it will be easy for people to find with a script. Maybe better to just add a comment (either with or without your patch). > > There is also this in handle_rx_console(): > > unsigned char buf[sizeof(u32)]; > > James > > > > > > >> --- > >> 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; > >> } > > _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel