Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp3191995iob; Fri, 6 May 2022 22:03:39 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxvUjIqD0t2NqP/MJ/BnYL97MU5LKKM+vamgTZW9ZjvfXeSQH3mSdvc+1Lr9PFarAsTHDnU X-Received: by 2002:a05:6402:11c9:b0:422:b76c:bef8 with SMTP id j9-20020a05640211c900b00422b76cbef8mr7213777edw.238.1651899818770; Fri, 06 May 2022 22:03:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651899818; cv=none; d=google.com; s=arc-20160816; b=VGp5zSC9yMMprTDZJF8YRuKT7RSUgY0FnEPlNVADF452QvAF0sUSOA9W9oMZu5fqeU cbRjIebTMrUU2emcZNQimJ5tbTiheGE4dAg8Zef7ePR6OQG27UIFj6S2EjUq1SFlwOtp b0U243UgmkeusODFNJ3vxRFD8IyzhT23dFhJ9SWEVY7njEvbmPlCsygOgmOqYJQWhm8l RtjfQBXZefVovVp9MT7dyJ1ocZIHPeyZ2Lh9mK2YF/wzwXd3t2rymZM6Cz9EPuw53MbN HF1Xz7HQ2pa2l6s8wKqbCIhncyn0k4r9/SWDLbgCEflXHP9r6XfAC6eQHQZMRgso6tXL wKog== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:message-id:user-agent:references:in-reply-to :subject:cc:to:from:date:content-transfer-encoding:mime-version :dkim-signature; bh=X4UP6069upSAVdzEbZTvI/GU1SyPtbLZbn/Xr0OjFbY=; b=tzwf+KnKvtvix9C4fK6r03OUIY8NwDbIM2c4DRfwcIUnq/DBkIhlDRbuFeVwQ6xu+d sqi/QZS2gOFXznz18iG/DQ9yOJInpdL1h67ABiRbLZJGoeaAtvbmc7042bcuhUk+BtiW +duNWAtVr3Yq42dQRNdPIEYug2fxqHAfvc3bNu8NCK5vZohtsuFAqJH/bZ8PW2efmAi3 WRrdWEWyaIDzmSNFcg6x5WsAqAXUVpBL9jhU10dyWXhnZCJRpgt81FjXD3ck8tvdvS6I d8gf+2vag3WtBnpqbZ3eGozJwRVbRqBdl8SuvxJ1GcnsoI5Eo2AuaFmXv7MfhEva7SJs rgrw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@walle.cc header.s=mail2016061301 header.b=BeZQlslX; 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 iy3-20020a170907818300b006df76385d10si5945545ejc.432.2022.05.06.22.03.03; Fri, 06 May 2022 22:03:38 -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; dkim=pass header.i=@walle.cc header.s=mail2016061301 header.b=BeZQlslX; 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 S1380464AbiEEPPP (ORCPT + 99 others); Thu, 5 May 2022 11:15:15 -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 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS,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 [+ 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