Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp4646142iob; Sun, 8 May 2022 20:28:06 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzP/BiIQCIj3Rs0hH5i+nt1NAdm6M0RlWfdyMMWwTcxb/tMe2+ohZuMjzDXl/rs5hDoAVYj X-Received: by 2002:a17:903:11d0:b0:155:c240:a2c0 with SMTP id q16-20020a17090311d000b00155c240a2c0mr14204892plh.143.1652066886530; Sun, 08 May 2022 20:28:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652066886; cv=none; d=google.com; s=arc-20160816; b=HWvc26RsU2i8cePxJHZLfaOsqxY9VkWsimQVwgKpRSek/aTmYEcPPzo65a0Jlx87j+ FgKzhhf1RdXhrFYM80NNbwKsyRqix54tydGIMj0OBhGpeRXzkp/TgKFEP57YOFDKyTdA Q9OvD8/Jj33j5r9AAX5fvoBpFNtyOOnHpjq51FzcTNf1CzHXXPI1UBwqZFSJVCgKaFDJ VAjOq1XWaGfCM6wQfWdrMTFJyRNcWdfg/D8OHYzN9/Q+ajgcVrOn1wsGzPbX7g2nXjAx Gu+Ih+mNKcXRHwQtvQG9Qss3dXTNYaOTXilexgXOvbRYKHeoLBNp0g78jq0G3we4++sb MLZg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=iqSZhvZmh8HOBCaHc5o65IMVZfC4B4eW7/whuSgymoo=; b=M2AhXhWMqQcojKim4558rBrdmtNFHG/Vn8sX4UC10NPVt17pR7iZHk+Z1EgzL6YSPJ McQk7+y5pC549Vbui7CX3diTBEo6LIlZlJExYCDgbpVW1xkWCk6v3gYUUwFMhkeLdImz /2mCEGRxaUZssvsQEKrS03sWdHsBvQFqVFfgXlh5x3nJeur361OG1lcXf0eWei90iSK+ h1Nzqpz5fn42G428IhjbUzVjC6+Rr+iRySmBm5SfyyBgHrF8/sTT8hqyjckL/C/aENUM ythBjRYGzXqzGgwI5r2HdwchX5HVUrOu89ykawe0DQbO5kJb3on6VMkg9LadxIhstBx5 m6Fw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=YaaCc8Qx; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id m6-20020a170902db0600b0015d4d83f206si12018521plx.600.2022.05.08.20.28.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 08 May 2022 20:28:06 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=YaaCc8Qx; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id D129157103; Sun, 8 May 2022 20:26:11 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1380824AbiEEOz0 (ORCPT + 99 others); Thu, 5 May 2022 10:55:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46406 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1350734AbiEEOzZ (ORCPT ); Thu, 5 May 2022 10:55:25 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 877542CC83; Thu, 5 May 2022 07:51:45 -0700 (PDT) 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 2C1A36198B; 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 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> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220407150828.202513-1-michael@walle.cc> X-Spam-Status: No, score=-2.9 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable 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 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