Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp1840540iob; Thu, 5 May 2022 09:09:30 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx0rVS2ZE0BbeMl0cLxCCk/ZnV+XDtlC9Es6/WStaDflfPVklAamuNp7a18K0xEIdTRVNZu X-Received: by 2002:aa7:d954:0:b0:425:f621:f77f with SMTP id l20-20020aa7d954000000b00425f621f77fmr31083976eds.363.1651766969897; Thu, 05 May 2022 09:09:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651766969; cv=none; d=google.com; s=arc-20160816; b=0kDuCTGnfJXeXhj2HG5LQkHj8bDtbgmegl8p7wfWxYgtczLT0AM6UqysmIUhPt6RbQ fURhJFFzhmTObnBoyCzEp7HjMcuIAfCjvsH9IHqZxubuc/XoOhJtCNEOVu8NSqVRI0Bn u2dcbv1NQrLUMRqoon+0PF+4766hUH28B7FF0vTSYElpXgSIMinAXIftwUFfpx84y0BG ojhr9k6aNvGyY30pLAVS3I3rcI4Kq5L82qSzM7NG2bpGrUpAJr32MS9X7pcBIv+goBcI DsJ+JHoXIMFpFXagoti+TqQp56vHZ9cqOqkILugn13+WwplabekQNU+y/MRUmWBxeOOZ vUqQ== 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=E/FvmvJvPIo9YUhBwt4byv/L38zyaPDkNSh4508S7Tg=; b=IQi2XeYMKeMMTc7cQo3jYlrKglto24jHJeYXYy6HWt4eC83uZmNOTMq84BOFbSbwts ctj28mETGn3zEDJxajoHHdgNbNaEqvP3G4Qz5H2iDA+GmWs+YAefFINuVS8W6hv1P+sB J5jW7Z/N0XM8DxXP+gYNMWJB6mAq6pVVme0lrcUavUJYG4DC/e9c0avLdg4czsFffszM tX/JVxbe7XDWE8IU6xtklmzamzusPU8tRpVKz5enSNOqFttJfYgvLFCXqBAaoA2GH7gf eAJXegJqo1mBJwt3k7Oe7SmYuRRYY61P8dL1ZmxWre02CzhQb9vWuT+9Qdt0DAikvZ+g eS2A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=EuJrI7SO; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id gb41-20020a170907962900b006f50b98790asi1154696ejc.41.2022.05.05.09.09.05; Thu, 05 May 2022 09:09:29 -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=@kernel.org header.s=k20201202 header.b=EuJrI7SO; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1381234AbiEEPWD (ORCPT + 99 others); Thu, 5 May 2022 11:22:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45328 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347238AbiEEPWC (ORCPT ); Thu, 5 May 2022 11:22:02 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0A7B65676C; Thu, 5 May 2022 08:18:21 -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 ams.source.kernel.org (Postfix) with ESMTPS id BCF7CB82DBB; Thu, 5 May 2022 15:18:20 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id CBF23C385AE; Thu, 5 May 2022 15:18:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1651763899; bh=BSLHwZBU7CEcphBe/qi0nQ6hse+0DaLEQ9dWC+R/3Fc=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=EuJrI7SOU5Y/UcoEhlXrTw6pKOQ0AMRNAdrLI8NhFbPYVnDqpyFZBpA1gqepEkxZN bvvH6XGUgEOAU5/weZia3rDkML8glIxPAzFij2pwQP75xBfwZ3xJo7SMqMVg+R09Sn 5rkCau7yV2ibfVTurh6YLgJvoOLa4vTdhHcnxmI9PCGpM2y3FTeST6TcsDGdWLz5OX Yk0K99EeTAcCAcSvI/A40vnGeicpMjeK42bmvMZ+Xa8d64Fi+Digwj1UrhWo4U/nwz flMRmQgjS0gH5ApSf35HEqY+HAV+dx9b7oeI2Fg/mVW5uaecVh9/q/5gmYq5tQ7Fdw 5AVkxyu8gFfDA== Date: Thu, 5 May 2022 08:18:17 -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, Wolfram Sang Subject: Re: [PATCH v2] i2c: at91: use dma safe buffers Message-ID: References: <20220407150828.202513-1-michael@walle.cc> <54f02090e6621460b66dc9d233d53283@walle.cc> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <54f02090e6621460b66dc9d233d53283@walle.cc> X-Spam-Status: No, score=-7.7 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, 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 On Thu, May 05, 2022 at 05:11:30PM +0200, Michael Walle wrote: > [+ 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? I can send a patch, thank you for the input! Cheers, Nathan