Received: by 2002:ac0:a591:0:0:0:0:0 with SMTP id m17-v6csp523589imm; Sat, 7 Jul 2018 02:31:44 -0700 (PDT) X-Google-Smtp-Source: AAOMgpf2WgDPwNLghkErkOCsYVrK7xhHpkkAutMp6I8hTSp+i/WXF1zG1d7L1oOYnA6JK41Zyffw X-Received: by 2002:a65:5b8e:: with SMTP id i14-v6mr7609398pgr.242.1530955904354; Sat, 07 Jul 2018 02:31:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530955904; cv=none; d=google.com; s=arc-20160816; b=l3P79KpLigsXF70TLT/b+hn8tAXaitDbfZX+c3on0E7+IBWL655/lR//KskuZoG7Cj H4mSnetjm0ZFFydgjPT5XJYDI9k1hurpykPbk3/akrmjSqOWNnn1XTnrvJUpBaOZbCM5 d1fD97pxjvW0rtFAxc3JDkGZckXQnhoq3hBuAnLGs/b7S3oi8CzyS67THdLP1fysvDvd yI9Z+9kfXaxF6wdlgN8aFmuC8bgtw34GyHgOVk/QqATnlHqTXlWCdmk8Kd4K5vFiZl1F GtM4EdV4yuqw/ELl6HM/OpTuF9alxEotX+stdubgJLHw/Dikyv6QJrvoZXSqDTWio16d BIGg== 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=xqreKTCF4io+aa77NrgoX+ULZAglBNxI3o/rPj6KVcFt9pdLqABrA3hsrxMPmyQrxp o/Sp/y+RCjfzYyvDtzwmMHiMbvssVCzPZ/stWhFQwBIm81JhGy87uzm3Sj//ks/XR6mR PF78nTISczFYj5K26tQb3k/LUq9NVxQdJ7ve9/Amsd9Ro285It6GDrUaAImE/7IEeg4c FbBpdwwZznHWKHd7ZbqvBW3PpHR5lsRf4bClQf7WTmCAKbEQMuimvIqgUzUbv/Jg2MvY zoIAMAxW93GG9NazhnqvlKXnhggt9S2d9TUkq2t5/ohz0xFsbLkWXmRXuVcjHdh2It0s 2snQ== 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 v14-v6si6926342pga.270.2018.07.07.02.31.19; Sat, 07 Jul 2018 02:31:44 -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 S1753567AbeGGJaS (ORCPT + 99 others); Sat, 7 Jul 2018 05:30:18 -0400 Received: from mailgw02.mediatek.com ([210.61.82.184]:8603 "EHLO mailgw02.mediatek.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1751964AbeGGJaP (ORCPT ); Sat, 7 Jul 2018 05:30:15 -0400 X-UUID: 0f6443ad69ed4103b5c3f84fedec6092-20180707 Received: from mtkexhb01.mediatek.inc [(172.21.101.102)] by mailgw02.mediatek.com (envelope-from ) (mhqrelay.mediatek.com ESMTP with TLS) with ESMTP id 2078717432; Sat, 07 Jul 2018 17:30:07 +0800 Received: from mtkcas07.mediatek.inc (172.21.101.84) by mtkmbs03n1.mediatek.inc (172.21.101.181) with Microsoft SMTP Server (TLS) id 15.0.1210.3; Sat, 7 Jul 2018 17:30:06 +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 17:30:05 +0800 From: Jun Gao To: Wolfram Sang CC: , , , , , , Jun Gao Subject: [PATCH v2 2/3] i2c: Add helper to ease DMA handling Date: Sat, 7 Jul 2018 17:29:54 +0800 Message-ID: <1530955795-17714-3-git-send-email-jun.gao@mediatek.com> X-Mailer: git-send-email 1.8.1.1.dirty In-Reply-To: <1530955795-17714-1-git-send-email-jun.gao@mediatek.com> References: <1530955795-17714-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