Hi, On 6/22/24 5:35 PM, Pali Rohár wrote: > On Friday 21 June 2024 14:24:58 Hans de Goede wrote: >> +static void smo8800_instantiate_i2c_client(struct work_struct *work) >> +{ >> + struct smo8800_device *smo8800 = >> + container_of(work, struct smo8800_device, i2c_work); >> + const struct dmi_system_id *lis3lv02d_dmi_id; >> + struct i2c_board_info info = { }; >> + struct i2c_adapter *adap = NULL; >> + >> + if (smo8800->i2c_dev) >> + return; >> + >> + bus_for_each_dev(&i2c_bus_type, NULL, &adap, smo8800_find_i801); >> + if (!adap) >> + return; >> + >> + lis3lv02d_dmi_id = dmi_first_match(smo8800_lis3lv02d_devices); > > Result of this function call is always same. You can call it just once, > e.g. in module __init section and store cached result. This function will only run when a new main i2c-i801 adapter shows up. Which normally only happens once per boot, so there is no need to make things more complex to optimize this. Regards, Hans > >> + if (!lis3lv02d_dmi_id) >> + goto out_put_adapter; >> + >> + info.addr = (long)lis3lv02d_dmi_id->driver_data; >> + strscpy(info.type, "lis3lv02d", I2C_NAME_SIZE); >> + >> + smo8800->i2c_dev = i2c_new_client_device(adap, &info); >> + if (IS_ERR(smo8800->i2c_dev)) { >> + dev_err(smo8800->dev, "error %ld registering %s i2c_client\n", >> + PTR_ERR(smo8800->i2c_dev), info.type); >> + smo8800->i2c_dev = NULL; >> + } else { >> + dev_dbg(smo8800->dev, "registered %s i2c_client on address 0x%02x\n", >> + info.type, info.addr); >> + } >> + >> +out_put_adapter: >> + i2c_put_adapter(adap); >> +} >