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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0A860C433F5 for ; Thu, 5 May 2022 15:11:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1381094AbiEEPPQ (ORCPT ); Thu, 5 May 2022 11:15:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37620 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231680AbiEEPPO (ORCPT ); Thu, 5 May 2022 11:15:14 -0400 Received: from ssl.serverraum.org (ssl.serverraum.org [176.9.125.105]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A3172BC0F; Thu, 5 May 2022 08:11:33 -0700 (PDT) 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 Content-Type: text/plain; charset=US-ASCII; format=flowed Content-Transfer-Encoding: 7bit Date: Thu, 05 May 2022 17:11:30 +0200 From: Michael Walle To: Nathan Chancellor Cc: Codrin Ciubotariu , Nicolas Ferre , Alexandre Belloni , Claudiu Beznea , linux-i2c@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, llvm@lists.linux.dev, Wolfram Sang 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 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.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