Received: by 2002:a05:6a10:83d0:0:0:0:0 with SMTP id o16csp47770pxh; Thu, 7 Apr 2022 13:34:40 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxYtI2fAJWcJ/uPEskrDTpGfgD2ajTAW8NF/g3vNdGoBURv0NS8G4KN33Y9yVLcOlpDoQ8a X-Received: by 2002:a17:903:2c5:b0:14f:4a29:1f64 with SMTP id s5-20020a17090302c500b0014f4a291f64mr15648136plk.90.1649363680253; Thu, 07 Apr 2022 13:34:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649363680; cv=none; d=google.com; s=arc-20160816; b=zYIQkikY/ktIncdLBUwxFpUbFbddzotKwp5T+6KaXTjJgJLAFXiKySVafwoXlMgnb6 xtb5BTxTwDtJ9uAIJxLrFcx5A0xRv61Wwjk6klzUF2UWhqiMxK87BMgTupBcVdrwxPo/ MMoCze8aQh8k0ZOpSrNYm/mtuTBCLfJ5k+xyfNYgUJpoxdhNBzRycVrHgJVHZVmyg7Xs 9jzXeI9R0XWcMiccpXq3AzycBAWk4O46/SkhS1psGuF3Zykfczw/uzFvMmTClem1cNcV JkJakpjQaesdKn1btgiaoabTQAufMsS4QAZr3Q460doM1Ra+LgaQh3XT5JNvQvfQo1Rv mE2w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=tQgmb/LuyMT3VXe63TOPkCXmIDA8njB/dP3LRniRTRY=; b=D4PFnSzLQx8vwvplyanzO9FoESFLx/JgFq/Gcw9J6gWiQroyvugHRI6Tzi2sz+V0Ow Nb2StOjvN8JcnNov/o4mRBcFs44YfWoCgaNwIiGo2yFRPJDYZKr3HTMFQy1UjV+btEjQ 7N1l/h9IAm7hNJhZbkEljZpyVusKkbf+sMw9cAbWx6WegXolYK0P7XjBCFaA5qHVBCS2 erMb/4PduZtQ7gfzaVDzTRPZoRxCXn6sKmqGERK3z5d9A6nTpOnNDv13f5fEXhpI6d56 xyEiS3dgf2B8j9F1ekOMPa3l3EMH7PuMD2opiiIhu67f7Eu/SL3AJH+Jrj3srGE/xP9C Lp4A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@walle.cc header.s=mail2016061301 header.b=KffbhpKE; 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 Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id 95-20020a17090a0fe800b001cac43b54c3si2455871pjz.150.2022.04.07.13.34.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Apr 2022 13:34:40 -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=@walle.cc header.s=mail2016061301 header.b=KffbhpKE; 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 Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 51E5B399734; Thu, 7 Apr 2022 12:47:06 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344481AbiDGPKo (ORCPT + 99 others); Thu, 7 Apr 2022 11:10:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55826 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344483AbiDGPKk (ORCPT ); Thu, 7 Apr 2022 11:10:40 -0400 Received: from ssl.serverraum.org (ssl.serverraum.org [IPv6:2a01:4f8:151:8464::1:2]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C32E01F9A1A; Thu, 7 Apr 2022 08:08:35 -0700 (PDT) Received: from mwalle01.kontron.local. (unknown [213.135.10.150]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by ssl.serverraum.org (Postfix) with ESMTPSA id 8382322175; Thu, 7 Apr 2022 17:08:32 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=walle.cc; s=mail2016061301; t=1649344112; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=tQgmb/LuyMT3VXe63TOPkCXmIDA8njB/dP3LRniRTRY=; b=KffbhpKEtWD3MumknEPUDhxyB/ECFkwceZV/zhR+VzE4uYvZ1jhE8HvbfqQSoD9kZL6cK8 pN5Z5v2ZMf6Fk++Mn+cGQLzWEhT546N/LZHeNsjqutcsBQDwIcgY2TBrFuNI47ZlGARjfe cNzBZW/EjBlGqF6jL49h9UpxfsZTE94= From: Michael Walle To: Codrin Ciubotariu , Nicolas Ferre , Alexandre Belloni , Claudiu Beznea Cc: linux-i2c@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Michael Walle Subject: [PATCH v2] i2c: at91: use dma safe buffers Date: Thu, 7 Apr 2022 17:08:28 +0200 Message-Id: <20220407150828.202513-1-michael@walle.cc> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE, URIBL_BLOCKED autolearn=no 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 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