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 BAE0BC4332F for ; Thu, 5 May 2022 15:12:52 +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-Type: Content-Transfer-Encoding:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:Message-ID:References:In-Reply-To:Subject:To:From: Date:MIME-Version:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=CilPgjRKAXuI4Mf4Iw5N0FZvP8fgpfQOxZSH7TrriCw=; b=MTa254WKaLZT4kIrEzwcYX+unm RVuJSZSBqvlhGbnTZGeg4F7/NqVqWdcYq+6WZU+a4KTZ+qvccGGBW4aEQP+LQYrjFFnRD6mOJE/VK PSfelllHkjnRofZMFfpywgYKduYX7T5O87g7QZMviey9ZOdxUO50gm2OJ4EEj2FCHYb0Efd8ZP2b+ 4nQrMT3iKFkc5zVzdosNxVuoOQa0H2KkxWGUy2b1bE2mvKiSWpy9fmUls/fdq3mHj/fXwzPVgY8nh 3cXj3KHJIZYVbcCbfK956MVvovHbjmy3thx76JSyj+9ggUWSs+zfDHOSxKjBF0LWTGwsQKh679Unb MZnCpDQg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nmd8n-00GaL2-0E; Thu, 05 May 2022 15:11:41 +0000 Received: from ssl.serverraum.org ([2a01:4f8:151:8464::1:2]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nmd8i-00GaIi-QI for linux-arm-kernel@lists.infradead.org; Thu, 05 May 2022 15:11:38 +0000 Received: from ssl.serverraum.org (web.serverraum.org [172.16.0.2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ssl.serverraum.org (Postfix) with ESMTPSA id 1A2F422205; Thu, 5 May 2022 17:11:31 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=walle.cc; s=mail2016061301; t=1651763491; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=X4UP6069upSAVdzEbZTvI/GU1SyPtbLZbn/Xr0OjFbY=; b=BeZQlslXr2cadlkcDPbqpc6/U+6AVHRWEs/66Sc2QarlHx6v24hKjpcbOKRtHoFY1C+L7z rn3PVUDns8G0M8nCA6J7+EIoshXhE2vskY8iNUI0wPFsz4ORWSRU++1XituRXaZK3SaUeW 5ubR0UeMuiZqw18zEnmvGT5RDe/w0Zs= MIME-Version: 1.0 Date: Thu, 05 May 2022 17:11:30 +0200 From: Michael Walle To: Nathan Chancellor Subject: Re: [PATCH v2] i2c: at91: use dma safe buffers In-Reply-To: References: <20220407150828.202513-1-michael@walle.cc> User-Agent: Roundcube Webmail/1.4.13 Message-ID: <54f02090e6621460b66dc9d233d53283@walle.cc> X-Sender: michael@walle.cc X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220505_081137_083554_9975E35F X-CRM114-Status: GOOD ( 20.52 ) 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: , Cc: Alexandre Belloni , llvm@lists.linux.dev, linux-kernel@vger.kernel.org, Wolfram Sang , linux-i2c@vger.kernel.org, Codrin Ciubotariu , Claudiu Beznea , linux-arm-kernel@lists.infradead.org Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="us-ascii"; Format="flowed" Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org [+ Wolfram] Am 2022-05-05 16:51, schrieb Nathan Chancellor: > On Thu, Apr 07, 2022 at 05:08:28PM +0200, Michael Walle wrote: >> The supplied buffer might be on the stack and we get the following >> error >> message: >> [ 3.312058] at91_i2c e0070600.i2c: rejecting DMA map of vmalloc >> memory >> >> Use i2c_{get,put}_dma_safe_msg_buf() to get a DMA-able memory region >> if >> necessary. >> >> Fixes: 60937b2cdbf9 ("i2c: at91: add dma support") >> Signed-off-by: Michael Walle >> Reviewed-by: Codrin Ciubotariu >> --- >> changes since v1: >> - remove extra empty line >> - add fixes tag as suggested by Codrin >> >> drivers/i2c/busses/i2c-at91-master.c | 11 +++++++++++ >> 1 file changed, 11 insertions(+) >> >> diff --git a/drivers/i2c/busses/i2c-at91-master.c >> b/drivers/i2c/busses/i2c-at91-master.c >> index b0eae94909f4..5eca3b3bb609 100644 >> --- a/drivers/i2c/busses/i2c-at91-master.c >> +++ b/drivers/i2c/busses/i2c-at91-master.c >> @@ -656,6 +656,7 @@ static int at91_twi_xfer(struct i2c_adapter *adap, >> struct i2c_msg *msg, int num) >> unsigned int_addr_flag = 0; >> struct i2c_msg *m_start = msg; >> bool is_read; >> + u8 *dma_buf; >> >> dev_dbg(&adap->dev, "at91_xfer: processing %d messages:\n", num); >> >> @@ -703,7 +704,17 @@ static int at91_twi_xfer(struct i2c_adapter >> *adap, struct i2c_msg *msg, int num) >> dev->msg = m_start; >> dev->recv_len_abort = false; >> >> + if (dev->use_dma) { >> + dma_buf = i2c_get_dma_safe_msg_buf(m_start, 1); >> + if (!dma_buf) { >> + ret = -ENOMEM; >> + goto out; >> + } >> + dev->buf = dma_buf; >> + } >> + >> ret = at91_do_twi_transfer(dev); >> + i2c_put_dma_safe_msg_buf(dma_buf, m_start, !ret); >> >> ret = (ret < 0) ? ret : num; >> out: >> -- >> 2.30.2 >> >> > > This change as commit 03fbb903c8bf ("i2c: at91: use dma safe buffers") > causes the following clang warning: Ugh.. > drivers/i2c/busses/i2c-at91-master.c:707:6: error: variable 'dma_buf' > is used uninitialized whenever 'if' condition is false > [-Werror,-Wsometimes-uninitialized] > if (dev->use_dma) { > ^~~~~~~~~~~~ > drivers/i2c/busses/i2c-at91-master.c:717:27: note: uninitialized use > occurs here > i2c_put_dma_safe_msg_buf(dma_buf, m_start, !ret); > ^~~~~~~ > drivers/i2c/busses/i2c-at91-master.c:707:2: note: remove the 'if' if > its condition is always true > if (dev->use_dma) { > ^~~~~~~~~~~~~~~~~~ > drivers/i2c/busses/i2c-at91-master.c:659:13: note: initialize the > variable 'dma_buf' to silence this warning > u8 *dma_buf; > ^ > = NULL > 1 error generated. > > Should this variable be initialized or should the call to > i2c_put_dma_safe_msg_buf() be moved into the if statement? Initializing dma_buf with NULL should to the trick because i2c_put_dma_safe_msg_buf() is handling NULL gracefully. No need for an extra "if (dma_buf)". Will you take care or should I send a patch? -michael _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel