Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp909195pxb; Wed, 6 Apr 2022 04:01:04 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyK5/eBymNUnld5siwtZ4i6ZrhZWAkGS+ufEeQI5FPnUiRT3P6iQ2Ly+ktpUZpZ1xV73yrf X-Received: by 2002:a17:90a:558a:b0:1ca:a819:d2d1 with SMTP id c10-20020a17090a558a00b001caa819d2d1mr9386725pji.126.1649242864057; Wed, 06 Apr 2022 04:01:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649242864; cv=none; d=google.com; s=arc-20160816; b=iYUYDWFwk7qkU2Oa6jMKaTBzsWjywoIlcWCnPnQzo7SqzAzYzdeyhpzQ7x4rnuC9td uAchvUHA0PQzjuaejCtRRhebKZZFJHOJMxlTv/aNCOVREz8O6w5YYOmgn6C0119qGxyu jQhcTVJAu0HPn2FhAwYQoTg029/olHV0z1hEqDhIcrYKVoXBwiVD2yc59GB1sJCOd7qr USN6ZxA1otRmYvDZVrf7Ft9JZMnilDmkod82yYSenSSNeySghMqkbiRGsGhzkOlYp/sT OnFv2Kcq+r2pUuBRjf4ZoSxrMOrqFQD4cFhoRj+Ii9xtFcf5PbTecYYpJhOBU95Jk69p 4zUQ== 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=+6+1BpQJhWpIwzeox1bohwEoCNti4GjMewSwLvafwXw=; b=WnuDnRtnXLoOIFwftL8BMZgD+1TuRcZpk4Z4a7ygb5ANKartWSzG6z8ysQmNBU51Sw Bldo4qPggClytHh6gw6pH5VZoQhis7tmtCPqN7yoWTjAjNRJszBcKZwByGCwpp4uyFLp azBQN4W60OnwGUCNzU+YsCzZdfHLaiYt91hs0ExDdhw0iXFbNOnuisEoaLupuZkNM2Fa kAm6t7E6MmT1+CcN/x7fOk6e0SeshuHqlI4UVW2oP9fVMFN2tlF/JphJgKfKSdXOSzgz siiGETZ08C4ElwfNlUT0Ar74QkicTA9Swvne4kCUVP/BkCROncsp4LYqSQABKOcdz4DL 4DOA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@walle.cc header.s=mail2016061301 header.b=FjoEbM8+; 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 k82-20020a628455000000b004fe3d0e5d61si5017905pfd.359.2022.04.06.04.01.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Apr 2022 04:01:04 -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=FjoEbM8+; 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 38D1350BB69; Wed, 6 Apr 2022 02:23:59 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241922AbiDEXnd (ORCPT + 99 others); Tue, 5 Apr 2022 19:43:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60236 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1445342AbiDEPmv (ORCPT ); Tue, 5 Apr 2022 11:42:51 -0400 Received: from ssl.serverraum.org (ssl.serverraum.org [176.9.125.105]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 705A717E05; Tue, 5 Apr 2022 07:08: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 E473822247; Tue, 5 Apr 2022 16:08:30 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=walle.cc; s=mail2016061301; t=1649167711; 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=+6+1BpQJhWpIwzeox1bohwEoCNti4GjMewSwLvafwXw=; b=FjoEbM8+1cMTX7ixD4Mw3f9fWtrhCqWB0k1AAf2hdMX7f6oCWMT1wXPAY4BKHa7SJ2Uefh nRiJDlkMvxeECN0Hz+B+LZR9gyrz/dw/HfgISScMlZbgJrgFBhpSvJfVcPMr+lyrzY+sRR 5CsvQ+iUunnCwjuq9CnFA29BcFB2G4c= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Date: Tue, 05 Apr 2022 16:08:30 +0200 From: Michael Walle To: Codrin.Ciubotariu@microchip.com Cc: Nicolas.Ferre@microchip.com, alexandre.belloni@bootlin.com, Claudiu.Beznea@microchip.com, sumit.semwal@linaro.org, christian.koenig@amd.com, linux-i2c@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-media@vger.kernel.org, dri-devel@lists.freedesktop.org, linaro-mm-sig@lists.linaro.org, stable@vger.kernel.org Subject: Re: [PATCH] i2c: at91: use dma safe buffers In-Reply-To: <74494dda-e0cd-aa73-7e58-e4359c1ba292@microchip.com> References: <20220303161724.3324948-1-michael@walle.cc> <46e1be55-9377-75b7-634d-9eadbebc98d7@microchip.com> <360914ee-594c-86bc-2436-aa863a67953a@microchip.com> <27f124c9adaf8a4fbdfb7a38456c4a2e@walle.cc> <74494dda-e0cd-aa73-7e58-e4359c1ba292@microchip.com> User-Agent: Roundcube Webmail/1.4.13 Message-ID: <9e715ed06a28165446e29483cca7e3d0@walle.cc> X-Sender: michael@walle.cc 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 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 Am 2022-04-05 15:58, schrieb Codrin.Ciubotariu@microchip.com: > On 05.04.2022 14:09, Michael Walle wrote: >> Am 2022-04-05 12:02, schrieb Codrin.Ciubotariu@microchip.com: >>> On 05.04.2022 12:38, Michael Walle wrote: >>>> Am 2022-04-05 11:23, schrieb Codrin.Ciubotariu@microchip.com: >>>>>> +       if (dev->use_dma) { >>>>>> +               dma_buf = i2c_get_dma_safe_msg_buf(m_start, 1); >>>>> >>>>> If you want, you could just dev->buf = i2c_get_dma_safe... >>>> >>>> But where is the error handling in that case? dev->buf will >>>> be NULL, which is eventually passed to dma_map_single(). >>>> >>>> Also, I need the dma_buf for the i2c_put_dma_safe_msg_buf() >>>> call anyway, because dev->buf will be modified during >>>> processing. >>> >>> You still: >>>       if (!dev->buf) { >>>               ret = -ENOMEM; >>>               goto out; >>>       } >>> >>> So, at91_do_twi_transfer()/dma_map_single() will not be called. >> >> Ahh, I misunderstood you. Yes, but as I said, I need the dma_buf >> temporary variable anyway, because dev->buf is modified, eg. see >> at91_twi_read_data_dma_callback(). > at91_twi_read_data_dma_callback() is called as callback if > dma_async_issue_pending(dma->chan_rx) is called. > dma_async_issue_pending(dma->chan_rx) is called on > at91_twi_read_data_dma(), which is called in at91_do_twi_transfer(), > which we decided above to skip in case of error. It is not about errors, you need the exact same pointer you got from i2c_get_dma_safe_msg_buf() to be passed to i2c_put_dma_safe_msg_buf(). And because (in some cases, it isn't really obvious) the dev->buf will be advanced a few bytes, I cannot pass dev->buf to i2c_put_dma_safe_msg_buf(). -michael