From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EB11C625 for ; Thu, 5 May 2022 14:51:44 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0CB37C385AE; Thu, 5 May 2022 14:51:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1651762304; bh=UYCZjEShRpoFfzDqVuQUnq+KLuye9U/K272vgc4gV+M=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=YaaCc8QxzSWDamM6l1uMJ+YHmA7aOpzQANULytCi/9o5dCqw1RSPG0BR8oFdVnyUF 0i7G3r879MfJ5V77awaQ7LC5UlfJkinLk+x5CMGge7jX6r9C4TxPDReme5nTSk9O5S LiSdMJn8FEwGCq+H7IHWwD6YTLZVPqA8E9SBPRwoJCQcjlco142d+bUuL8/yRpAeFS HTnfB+sQNA56TnlnoTZD8YpnEP07ihKWnGrYUMio0DwWlxAlOIfUGIcLJZeREAOSfW 7f3XgH12q4KaIrFhOB4kr654GI/2VXtYYYwJmlG+8fwYeDLzVX4ZtJ4Nr4JhDUUcjZ hkEVYZlT/UfTA== Date: Thu, 5 May 2022 07:51:42 -0700 From: Nathan Chancellor To: Michael Walle 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 Subject: Re: [PATCH v2] i2c: at91: use dma safe buffers Message-ID: References: <20220407150828.202513-1-michael@walle.cc> Precedence: bulk X-Mailing-List: llvm@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220407150828.202513-1-michael@walle.cc> 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: 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? Cheers, Nathan 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 15FFBC433F5 for ; Thu, 5 May 2022 14:53:06 +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:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject: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=EiqueMgJQypJgNUijbK74wpZklRm7U5vCZ8phAHQMzs=; b=fXJrRy2613cHMO 7M+iY4gzQRNj2SnRZ9UB0Jo37vrBBgWrb9I7zaLjddSUVKQiV2zVm1QVHj84pW2RtGUXVZpaMq3or wd5hIcgk+PUNcCVC6tsVQyjdn7I2HEFohlRHU9HJLpiircncFM/N7hgM4wsKS/hjCPYxyct+MKOpS IznxKCYRfLI3pOZuDBucggd7D/rsmoOWhLIW0MlcCo8bFOxYDGwrzK1eif0Wf3sd9cYLZxUz0I+oN v67ac9V1sDfNhdDGtqmhLp8eb0ncnkTku0tYi+xqWMbyvhxlSYzg+I30msIyxto9tk1C8WnNkSLKR G9G0Mxw9ck72YUHSZunQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nmcpd-00GT9d-Ks; Thu, 05 May 2022 14:51:53 +0000 Received: from ams.source.kernel.org ([2604:1380:4601:e00::1]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nmcpZ-00GT76-Du for linux-arm-kernel@lists.infradead.org; Thu, 05 May 2022 14:51:51 +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 ams.source.kernel.org (Postfix) with ESMTPS id E36A0B82D7A; Thu, 5 May 2022 14:51:45 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0CB37C385AE; Thu, 5 May 2022 14:51:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1651762304; bh=UYCZjEShRpoFfzDqVuQUnq+KLuye9U/K272vgc4gV+M=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=YaaCc8QxzSWDamM6l1uMJ+YHmA7aOpzQANULytCi/9o5dCqw1RSPG0BR8oFdVnyUF 0i7G3r879MfJ5V77awaQ7LC5UlfJkinLk+x5CMGge7jX6r9C4TxPDReme5nTSk9O5S LiSdMJn8FEwGCq+H7IHWwD6YTLZVPqA8E9SBPRwoJCQcjlco142d+bUuL8/yRpAeFS HTnfB+sQNA56TnlnoTZD8YpnEP07ihKWnGrYUMio0DwWlxAlOIfUGIcLJZeREAOSfW 7f3XgH12q4KaIrFhOB4kr654GI/2VXtYYYwJmlG+8fwYeDLzVX4ZtJ4Nr4JhDUUcjZ hkEVYZlT/UfTA== Date: Thu, 5 May 2022 07:51:42 -0700 From: Nathan Chancellor To: Michael Walle Subject: Re: [PATCH v2] i2c: at91: use dma safe buffers Message-ID: References: <20220407150828.202513-1-michael@walle.cc> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20220407150828.202513-1-michael@walle.cc> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220505_075149_798183_7E23A25B X-CRM114-Status: GOOD ( 23.51 ) 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, linux-i2c@vger.kernel.org, Codrin Ciubotariu , Claudiu Beznea , linux-arm-kernel@lists.infradead.org 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 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: 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? Cheers, Nathan _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel