linux-i2c.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Yicong Yang <yangyicong@hisilicon.com>
To: Dmitry Osipenko <digetx@gmail.com>, <wsa@kernel.org>,
	<linux-i2c@vger.kernel.org>
Cc: <andriy.shevchenko@linux.intel.com>, <treding@nvidia.com>,
	<jarkko.nikula@linux.intel.com>, <rmk+kernel@armlinux.org.uk>,
	<song.bao.hua@hisilicon.com>, <john.garry@huawei.com>,
	<prime.zeng@huawei.com>, <linuxarm@huawei.com>
Subject: Re: [PATCH v3 1/3] i2c: core: add managed function for adding i2c adapters
Date: Wed, 24 Mar 2021 16:29:26 +0800	[thread overview]
Message-ID: <23efcf01-5d04-242e-8574-bb9a5ef5face@hisilicon.com> (raw)
In-Reply-To: <c306cfc0-8574-9903-af4e-f27b99888d03@gmail.com>

On 2021/3/23 0:45, Dmitry Osipenko wrote:
> 22.03.2021 14:10, Yicong Yang пишет:
>> 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.
>>
>> Signed-off-by: Yicong Yang <yangyicong@hisilicon.com>
>> ---
>>  drivers/i2c/i2c-core-base.c | 39 +++++++++++++++++++++++++++++++++++++++
>>  include/linux/i2c.h         |  1 +
>>  2 files changed, 40 insertions(+)
>>
>> diff --git a/drivers/i2c/i2c-core-base.c b/drivers/i2c/i2c-core-base.c
>> index 63ebf72..61486dc 100644
>> --- a/drivers/i2c/i2c-core-base.c
>> +++ b/drivers/i2c/i2c-core-base.c
>> @@ -1550,6 +1550,38 @@ int i2c_add_adapter(struct i2c_adapter *adapter)
>>  }
>>  EXPORT_SYMBOL(i2c_add_adapter);
>>  
>> +static void devm_i2c_del_adapter(struct device *dev, void *ptr);
>> +
>> +/**
>> + * 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)
>> +{
>> +	struct i2c_adapter **ptr;
>> +	int ret;
>> +
>> +	ptr = devres_alloc(devm_i2c_del_adapter, sizeof(*ptr), GFP_KERNEL);
>> +	if (!ptr)
>> +		return -ENOMEM;
>> +
>> +	ret = i2c_add_adapter(adapter);
>> +	if (!ret) {
>> +		*ptr = adapter;
>> +		devres_add(dev, ptr);
>> +	} else {
>> +		devres_free(ptr);
>> +	}
> 
> This could be simplified using devm_add_action_or_reset().

thanks for the hint. i'll see whether i can change to that.

> 
>> +	return ret;
>> +}
>> +EXPORT_SYMBOL(devm_i2c_add_adapter);
> 
> EXPORT_SYMBOL_GPL

considering i2c_add_adapter exported with no GPL, i think the variant should
keep the same.

Thanks,
Yicong

> 
> .
> 


  reply	other threads:[~2021-03-24  8:30 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-22 11:10 [PATCH v3 0/3] Add support for HiSilicon I2C controller Yicong Yang
2021-03-22 11:10 ` [PATCH v3 1/3] i2c: core: add managed function for adding i2c adapters Yicong Yang
2021-03-22 16:35   ` Andy Shevchenko
2021-03-24  8:26     ` Yicong Yang
2021-03-24 11:05       ` Andy Shevchenko
2021-03-22 16:45   ` Dmitry Osipenko
2021-03-24  8:29     ` Yicong Yang [this message]
2021-03-24 11:06       ` Andy Shevchenko
2021-03-22 11:10 ` [PATCH v3 2/3] i2c: add support for HiSilicon I2C controller Yicong Yang
2021-03-22 15:21   ` Dmitry Osipenko
2021-03-24  9:30     ` Yicong Yang
2021-03-24 12:26       ` Dmitry Osipenko
2021-03-22 16:59   ` Andy Shevchenko
2021-03-24 10:07     ` Yicong Yang
2021-03-24 11:15       ` Andy Shevchenko
2021-03-22 17:04   ` Andy Shevchenko
2021-03-24 10:21     ` Yicong Yang
2021-03-24 11:16       ` Andy Shevchenko
2021-03-22 11:10 ` [PATCH v3 3/3] MAINTAINERS: Add maintainer for HiSilicon I2C driver Yicong Yang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=23efcf01-5d04-242e-8574-bb9a5ef5face@hisilicon.com \
    --to=yangyicong@hisilicon.com \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=digetx@gmail.com \
    --cc=jarkko.nikula@linux.intel.com \
    --cc=john.garry@huawei.com \
    --cc=linux-i2c@vger.kernel.org \
    --cc=linuxarm@huawei.com \
    --cc=prime.zeng@huawei.com \
    --cc=rmk+kernel@armlinux.org.uk \
    --cc=song.bao.hua@hisilicon.com \
    --cc=treding@nvidia.com \
    --cc=wsa@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).