Received: by 2002:ac0:a591:0:0:0:0:0 with SMTP id m17-v6csp280183imm; Fri, 6 Jul 2018 19:51:05 -0700 (PDT) X-Google-Smtp-Source: AAOMgpfhV/9pj7kMjJXyUPhkl5mRUS8tUdMAwsnpoGz8tyD8hdxvhW0MNPayZmTObWPJhaxpNTBL X-Received: by 2002:a63:9741:: with SMTP id d1-v6mr11073907pgo.403.1530931865336; Fri, 06 Jul 2018 19:51:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530931865; cv=none; d=google.com; s=arc-20160816; b=lYe2N7nhJfPE/2m5xjr+vhQBbk81cCEkAQq6uDJvLf2c23pE5FSBLLLqkswOIwrNWW SoJtrtFLhBjXmnpOBzHGUToBgdHPHnzDiSVrrXrSiMhKDza0Tx8YGzSbESN/jWDpM9DF T11hCHIjPn1C1cgGNoy4IyuvdivOYI8K5SmVxbxKmqhvvlay36p+limDdIgubJYO/fOB e9pmAh7QWoIQYcYKxBxal80aTVcMccUsmAmesGBDps72j5HHYe7m3qaQuIdeH3WyuAj2 QKx9ox5dTF5FD18mPrbLZ8c00luG+mdX3n8I+oQbu6mgSwEaXj3MmHF9oL9iWiAcLAPW 2VCA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:arc-authentication-results; bh=4UU9wVXALjWHwCM/vGcUHOgsxhUlxh06HaFI8xwDyYg=; b=iBQ1fHBolUPbSUxBmcm3wA7uuugRV49lXHTD72gSXwLMbQn/cuE3S3gYKSH8NPjY6B K7cfRLk4RcZTzHR/5U0WDDa3M1q6nEA+hScWQh33OyiFFDZ8igayQ1Scl6gh77xhZJ7q m1UmEy2EMalESU0/BE+CXfagQdFGs8CyUM7ZpPhND0Uq9F0AwGQASJFC619uxi/S7Pvx yrQleeM/rFtGO6gDhlEoKWu8HC/wWBJmxHAnnb1NBUgzWR1KdmLXRAjIui2YtCRsVW35 j3jCyeIXmrAmh1TUDWMP5GjNUFwG76bI+s15fx+DA/DEp0OniMkfldCed4EuQMPWCPIE 6sfw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h65-v6si9290031pfb.70.2018.07.06.19.50.51; Fri, 06 Jul 2018 19:51:05 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933166AbeGGCtt (ORCPT + 99 others); Fri, 6 Jul 2018 22:49:49 -0400 Received: from mailgw02.mediatek.com ([210.61.82.184]:38097 "EHLO mailgw02.mediatek.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S932908AbeGGCto (ORCPT ); Fri, 6 Jul 2018 22:49:44 -0400 X-UUID: 289db7c446474359b56eb666066a408c-20180707 Received: from mtkcas09.mediatek.inc [(172.21.101.178)] by mailgw02.mediatek.com (envelope-from ) (mhqrelay.mediatek.com ESMTP with TLS) with ESMTP id 2120990242; Sat, 07 Jul 2018 10:49:38 +0800 Received: from mtkcas07.mediatek.inc (172.21.101.84) by mtkmbs03n2.mediatek.inc (172.21.101.182) with Microsoft SMTP Server (TLS) id 15.0.1210.3; Sat, 7 Jul 2018 10:49:37 +0800 Received: from localhost.localdomain (10.17.3.153) by mtkcas07.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1210.3 via Frontend Transport; Sat, 7 Jul 2018 10:49:37 +0800 From: Jun Gao To: Wolfram Sang CC: , , , , , , Jun Gao Subject: [PATCH 2/3] i2c: Add helper to ease DMA handling Date: Sat, 7 Jul 2018 10:49:12 +0800 Message-ID: <1530931753-8264-3-git-send-email-jun.gao@mediatek.com> X-Mailer: git-send-email 1.8.1.1.dirty In-Reply-To: <1530931753-8264-1-git-send-email-jun.gao@mediatek.com> References: <1530931753-8264-1-git-send-email-jun.gao@mediatek.com> MIME-Version: 1.0 Content-Type: text/plain X-MTK: N Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Jun Gao This function is needed by i2c_get_dma_safe_msg_buf() potentially. It is used to free DMA safe buffer when DMA operation fails. Signed-off-by: Jun Gao --- drivers/i2c/i2c-core-base.c | 14 ++++++++++++++ include/linux/i2c.h | 1 + 2 files changed, 15 insertions(+) diff --git a/drivers/i2c/i2c-core-base.c b/drivers/i2c/i2c-core-base.c index 31d16ad..2b518ea 100644 --- a/drivers/i2c/i2c-core-base.c +++ b/drivers/i2c/i2c-core-base.c @@ -2288,6 +2288,20 @@ void i2c_release_dma_safe_msg_buf(struct i2c_msg *msg, u8 *buf) } EXPORT_SYMBOL_GPL(i2c_release_dma_safe_msg_buf); +/** + * i2c_free_dma_safe_msg_buf - free DMA safe buffer + * @msg: the message related to DMA safe buffer + * @buf: the buffer obtained from i2c_get_dma_safe_msg_buf(). May be NULL. + */ +void i2c_free_dma_safe_msg_buf(struct i2c_msg *msg, u8 *buf) +{ + if (!buf || buf == msg->buf) + return; + + kfree(buf); +} +EXPORT_SYMBOL_GPL(i2c_free_dma_safe_msg_buf); + MODULE_AUTHOR("Simon G. Vogl "); MODULE_DESCRIPTION("I2C-Bus main module"); MODULE_LICENSE("GPL"); diff --git a/include/linux/i2c.h b/include/linux/i2c.h index 254cd34..6d62f93 100644 --- a/include/linux/i2c.h +++ b/include/linux/i2c.h @@ -860,6 +860,7 @@ static inline u8 i2c_8bit_addr_from_msg(const struct i2c_msg *msg) u8 *i2c_get_dma_safe_msg_buf(struct i2c_msg *msg, unsigned int threshold); void i2c_release_dma_safe_msg_buf(struct i2c_msg *msg, u8 *buf); +void i2c_free_dma_safe_msg_buf(struct i2c_msg *msg, u8 *buf); int i2c_handle_smbus_host_notify(struct i2c_adapter *adap, unsigned short addr); /** -- 1.8.1.1