Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp414654pxf; Wed, 31 Mar 2021 06:40:47 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxuv5De3JTdKsfogPonjMQEmDhwQ6/UcpMme6xTM0L/tlDanIMNfMarG8McUh+tM6ktuxnu X-Received: by 2002:a05:6402:1c1b:: with SMTP id ck27mr3812859edb.223.1617198047140; Wed, 31 Mar 2021 06:40:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1617198047; cv=none; d=google.com; s=arc-20160816; b=mmq1jJ6iMy+3GepBlso66AdeZ+GcIYuCjDU7mIufi2qCK6hxlerqflhRw6+rUaqKhn jcKqvOFg6ByFqA6aT5cj1nzdUtqu5hrGkvPJ6Q/edhbz9r0J6YCbQZEiDUU2y8GrlnOL 1Pyuj7dz6tu+WWySt/xzFSMTRtAgTEuE3pSpoZ5tcwcDRYvD1EYz/pmCT44+U4t3hHMd K3fP+GKcaYd1WTik+Khgn1Yb/eVTveIXH9+FSE0QN50L3am6AMusZt2vNvUw8MBuJxis /g2F7B4G/xFuPPBwLmvXLeafUyNSQUVT1ou7BmRNfqgfKzHox76pRdZjDizcJbkUOHR5 piYA== 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=QiTKWsvJuqu/1D1Y3OY0zvm7RQKkFMln3rqrGxOB7jvBBjP07x55T10Y/ORPTdzBW6 rhXWaOXwoHicU/LfuYcGRRDud5GGKLIj3/A/4c+wbR7HZ/QOPLeUK0u7sMLaFDD815hF EDVfCldDHtopWT9UEMPCUbH8nGEPqT3ni/zpNRUV4e/SaP8s5oL1qrI7dkzrRpyRTWXy UepwNslx+wDlBegNrn8BKk7YaNzIaujEmj0+YZ8cU3pandbJsXKwy2uQnTy7VmzgIfzI GlR3jVXGe5HlvTFQ8iqZdEQcPDjApjUrF1Tfz943/TAUR9AAxfpnBb2v10iKtCAzZp0J 3zXw== 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 g8si1762695ejm.240.2021.03.31.06.40.24; Wed, 31 Mar 2021 06:40:47 -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 S235960AbhCaNjh (ORCPT + 99 others); Wed, 31 Mar 2021 09:39:37 -0400 Received: from szxga06-in.huawei.com ([45.249.212.32]:15416 "EHLO szxga06-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235793AbhCaNjO (ORCPT ); Wed, 31 Mar 2021 09:39:14 -0400 Received: from DGGEMS405-HUB.china.huawei.com (unknown [172.30.72.59]) by szxga06-in.huawei.com (SkyGuard) with ESMTP id 4F9S6b6jjDzlWnt; Wed, 31 Mar 2021 21:37:27 +0800 (CST) Received: from localhost.localdomain (10.67.165.24) by DGGEMS405-HUB.china.huawei.com (10.3.19.205) with Microsoft SMTP Server id 14.3.498.0; Wed, 31 Mar 2021 21:39:00 +0800 From: Yicong Yang To: , , , , CC: , , , , , , , , , Subject: [PATCH v6 1/5] i2c: core: add managed function for adding i2c adapters Date: Wed, 31 Mar 2021 21:36:26 +0800 Message-ID: <1617197790-30627-2-git-send-email-yangyicong@hisilicon.com> X-Mailer: git-send-email 2.8.1 In-Reply-To: <1617197790-30627-1-git-send-email-yangyicong@hisilicon.com> References: <1617197790-30627-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