Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp339001pxf; Thu, 8 Apr 2021 04:20:55 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwnVCCUgkVxD+TjzO5dc1M9vSDXzR+68K9/ehoHQ6iNLI4aV/gTBEDQQPZ79u9uyTs68flG X-Received: by 2002:a63:c450:: with SMTP id m16mr7482583pgg.333.1617880854825; Thu, 08 Apr 2021 04:20:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1617880854; cv=none; d=google.com; s=arc-20160816; b=TrYorIdmm0B7xuj+LXRKKH0ysJVgtel5lNGww4rbznfxDMvCydxAzSKHpLDCC3ulEh 9WmymwbT9nyvSrxvswnc12//UiRD66dTBqTHhc0eyWdEHh38hEffKgBaOo/vnkFQijkT 23KBZ5JJM7Dk3Cn9J+QZZMzJaVe8D54VqkclXIEQh+vXMTB0qiwzSXYKV11BRc9k75A9 WpOI2IBtuIWe42FxLJ5vNtmm0OaCqWfkfre2LCdagjCy/+xrk0Z/dFq/ICB33smQWVHc FPiIY+mBOA+jJEzPsKDKk5QmI9VNsI4vI/WBi8OwQnOqZ5igfD+M+9qMT8lVzkLBasz3 Km5A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from; bh=fczS+V86/O96crzX4wk7tHC3HdGSMEQ0MYH7LwDcTo4=; b=GxHjbMpbgfTOdNfbatmxw2l6akr2onkjGIAOHUbUzXRZKA2T32Y4hBRIIKu8h7N8yk /WwkueFH3xchYiH6+yOI8/SW7jRaANFNIyWrUk9BvIExfYznHJAoHGTnWu2fvO6ii6ah h6kKu8XJl8P6pFa8iHOKFijtIPRhsjBirr1OsWHgnvULdrtd3jwj13cyM2QO6CSV/EQA WAkOnDIMG+vBjqR+dzGjOrwyDX4X9+twaUjfhLp8wFDBx3NSaebPW9oJANjVOZ2r6dcw mvI9O3GBYx40foSlMy7/GORHTk0vh5xNu1wIx/XwTyWiOt5Mrb2TQIr/RfechJZ+E69D LEfw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=hisilicon.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id o12si3593449pgj.23.2021.04.08.04.20.42; Thu, 08 Apr 2021 04:20:54 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=hisilicon.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231235AbhDHLUR (ORCPT + 99 others); Thu, 8 Apr 2021 07:20:17 -0400 Received: from szxga04-in.huawei.com ([45.249.212.190]:15186 "EHLO szxga04-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230344AbhDHLUQ (ORCPT ); Thu, 8 Apr 2021 07:20:16 -0400 Received: from DGGEMS408-HUB.china.huawei.com (unknown [172.30.72.58]) by szxga04-in.huawei.com (SkyGuard) with ESMTP id 4FGJd71MCwzpWXf; Thu, 8 Apr 2021 19:17:15 +0800 (CST) Received: from localhost.localdomain (10.67.165.24) by DGGEMS408-HUB.china.huawei.com (10.3.19.208) with Microsoft SMTP Server id 14.3.498.0; Thu, 8 Apr 2021 19:19:55 +0800 From: Yicong Yang To: , , , , CC: , , , , , , , , , Subject: [PATCH v7 1/5] i2c: core: add managed function for adding i2c adapters Date: Thu, 8 Apr 2021 19:17:17 +0800 Message-ID: <1617880641-664-2-git-send-email-yangyicong@hisilicon.com> X-Mailer: git-send-email 2.8.1 In-Reply-To: <1617880641-664-1-git-send-email-yangyicong@hisilicon.com> References: <1617880641-664-1-git-send-email-yangyicong@hisilicon.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.67.165.24] X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Some I2C controller drivers will only unregister the I2C adapter in their .remove() callback, which can be done by simply using a managed variant to add the I2C adapter. So add the managed functions for adding the I2C adapter. Reviewed-by: Andy Shevchenko Reviewed-by: Dmitry Osipenko Signed-off-by: Yicong Yang --- drivers/i2c/i2c-core-base.c | 26 ++++++++++++++++++++++++++ include/linux/i2c.h | 1 + 2 files changed, 27 insertions(+) diff --git a/drivers/i2c/i2c-core-base.c b/drivers/i2c/i2c-core-base.c index 63ebf72..de9402c 100644 --- a/drivers/i2c/i2c-core-base.c +++ b/drivers/i2c/i2c-core-base.c @@ -1703,6 +1703,32 @@ void i2c_del_adapter(struct i2c_adapter *adap) } EXPORT_SYMBOL(i2c_del_adapter); +static void devm_i2c_del_adapter(void *adapter) +{ + i2c_del_adapter(adapter); +} + +/** + * devm_i2c_add_adapter - device-managed variant of i2c_add_adapter() + * @dev: managing device for adding this I2C adapter + * @adapter: the adapter to add + * Context: can sleep + * + * Add adapter with dynamic bus number, same with i2c_add_adapter() + * but the adapter will be auto deleted on driver detach. + */ +int devm_i2c_add_adapter(struct device *dev, struct i2c_adapter *adapter) +{ + int ret; + + ret = i2c_add_adapter(adapter); + if (ret) + return ret; + + return devm_add_action_or_reset(dev, devm_i2c_del_adapter, adapter); +} +EXPORT_SYMBOL_GPL(devm_i2c_add_adapter); + static void i2c_parse_timing(struct device *dev, char *prop_name, u32 *cur_val_p, u32 def_val, bool use_def) { diff --git a/include/linux/i2c.h b/include/linux/i2c.h index 5662265..10bd0b0 100644 --- a/include/linux/i2c.h +++ b/include/linux/i2c.h @@ -844,6 +844,7 @@ static inline void i2c_mark_adapter_resumed(struct i2c_adapter *adap) */ #if IS_ENABLED(CONFIG_I2C) int i2c_add_adapter(struct i2c_adapter *adap); +int devm_i2c_add_adapter(struct device *dev, struct i2c_adapter *adapter); void i2c_del_adapter(struct i2c_adapter *adap); int i2c_add_numbered_adapter(struct i2c_adapter *adap); -- 2.8.1