Re: [PATCH v6 1/6] i2c: core: Setup i2c_adapter runtime-pm before calling device_add()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi Hans,

...

> --- a/drivers/i2c/i2c-core-base.c
> +++ b/drivers/i2c/i2c-core-base.c
> @@ -1521,7 +1521,18 @@ static int i2c_register_adapter(struct i2c_adapter *adap)
>  	dev_set_name(&adap->dev, "i2c-%d", adap->nr);
>  	adap->dev.bus = &i2c_bus_type;
>  	adap->dev.type = &i2c_adapter_type;
> -	res = device_register(&adap->dev);
> +	device_initialize(&adap->dev);
> +
> +	/*
> +	 * This adapter can be used as a parent immediately after device_add(),
> +	 * setup runtime-pm (especially ignore-children) before hand.
> +	 */
> +	device_enable_async_suspend(&adap->dev);
> +	pm_runtime_no_callbacks(&adap->dev);
> +	pm_suspend_ignore_children(&adap->dev, true);
> +	pm_runtime_enable(&adap->dev);
> +
> +	res = device_add(&adap->dev);

I see a pattern here around in the kernel:

	device_initialize(...)
	...
	device_add(...)

which makes the device_register() helper not that useful. Perhaps
for the future we could add a device_register_fn() where we pass
the reference of a function that does whatever lies in between
the initialize and the add... food for thoughts.

As of now, looks good to me:

Reviewed-by: Andi Shyti <andi.shyti@xxxxxxxxxx>

Thanks,
Andi

>  	if (res) {
>  		pr_err("adapter '%s': can't register device (%d)\n", adap->name, res);
>  		goto out_list;
> @@ -1533,11 +1544,6 @@ static int i2c_register_adapter(struct i2c_adapter *adap)
>  	if (res)
>  		goto out_reg;
>  
> -	device_enable_async_suspend(&adap->dev);
> -	pm_runtime_no_callbacks(&adap->dev);
> -	pm_suspend_ignore_children(&adap->dev, true);
> -	pm_runtime_enable(&adap->dev);
> -
>  	res = i2c_init_recovery(adap);
>  	if (res == -EPROBE_DEFER)
>  		goto out_reg;
> -- 
> 2.45.1
> 




[Index of Archives]     [Linux GPIO]     [Linux SPI]     [Linux Hardward Monitoring]     [LM Sensors]     [Linux USB Devel]     [Linux Media]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux