On Mon, Mar 22, 2021 at 07:10:11PM +0800, Yicong Yang wrote: > 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. ... > +static void devm_i2c_del_adapter(struct device *dev, void *ptr); Can we instead of forward declaration simply move below to be after devm_i2c_del_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) > +{ > + 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); > + } > + > + return ret; > +} -- With Best Regards, Andy Shevchenko