Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Merge tag 'regmap-fix-v7.1-merge-window' of git://git.kernel.org/pub/scm/linux/kernel/git/broonie/regmap

Pull regmap fixes from Mark Brown:
"There's couple of patches here that came in since my pull request:

- What is effectively a quirk for shoehorning support for a wider
range of I2C regmaps on weirdly restricted SMBus controllers

- One minor fix for a memory leak on in error handling in the dummy
driver used by the KUnit tests"

* tag 'regmap-fix-v7.1-merge-window' of git://git.kernel.org/pub/scm/linux/kernel/git/broonie/regmap:
regmap: ram: fix memory leaks in __regmap_init_ram() on error
regmap-i2c: add SMBus byte/word reg16 bus for adapters lacking I2C_FUNC_I2C

+56 -1
+49
drivers/base/regmap/regmap-i2c.c
··· 303 303 .max_raw_write = I2C_SMBUS_BLOCK_MAX - 2, 304 304 }; 305 305 306 + /* 307 + * SMBus byte/word reg16 support for adapters that have SMBUS_BYTE_DATA 308 + * and SMBUS_WORD_DATA but lack I2C_FUNC_I2C and I2C_FUNC_SMBUS_I2C_BLOCK, 309 + * such as the AMD PIIX4. 310 + * 311 + * READ: set 16-bit EEPROM address via write_byte_data(addr_lo, addr_hi), 312 + * then sequentially read bytes via read_byte() (EEPROM auto- 313 + * increments the address pointer). Same as the I2C-block reg16 314 + * read path above. 315 + * 316 + * WRITE: encode the low address byte and data into a word transaction: 317 + * write_word_data(addr_hi, (data_byte << 8) | addr_lo). 318 + * Only single-byte writes are supported (one value per transaction). 319 + */ 320 + static int regmap_smbus_word_write_reg16(void *context, const void *data, 321 + size_t count) 322 + { 323 + struct device *dev = context; 324 + struct i2c_client *i2c = to_i2c_client(dev); 325 + u8 addr_hi, addr_lo, val; 326 + 327 + /* 328 + * data layout: [addr_hi, addr_lo, val0, val1, ...]. 329 + * Only single-byte value writes are supported; multi-byte would 330 + * require raw I2C (or repeated word writes with incrementing address). 331 + */ 332 + if (count != 3) 333 + return -EINVAL; 334 + 335 + addr_hi = ((u8 *)data)[0]; 336 + addr_lo = ((u8 *)data)[1]; 337 + val = ((u8 *)data)[2]; 338 + 339 + return i2c_smbus_write_word_data(i2c, addr_hi, 340 + cpu_to_le16(((u16)val << 8) | addr_lo)); 341 + } 342 + 343 + static const struct regmap_bus regmap_smbus_byte_word_reg16 = { 344 + .write = regmap_smbus_word_write_reg16, 345 + .read = regmap_i2c_smbus_i2c_read_reg16, 346 + .max_raw_read = I2C_SMBUS_BLOCK_MAX - 2, 347 + .max_raw_write = 1, 348 + }; 349 + 306 350 static const struct regmap_bus *regmap_get_i2c_bus(struct i2c_client *i2c, 307 351 const struct regmap_config *config) 308 352 { ··· 365 321 i2c_check_functionality(i2c->adapter, 366 322 I2C_FUNC_SMBUS_I2C_BLOCK)) 367 323 bus = &regmap_i2c_smbus_i2c_block_reg16; 324 + else if (config->val_bits == 8 && config->reg_bits == 16 && 325 + i2c_check_functionality(i2c->adapter, 326 + I2C_FUNC_SMBUS_BYTE_DATA | 327 + I2C_FUNC_SMBUS_WORD_DATA)) 328 + bus = &regmap_smbus_byte_word_reg16; 368 329 else if (config->val_bits == 16 && config->reg_bits == 8 && 369 330 i2c_check_functionality(i2c->adapter, 370 331 I2C_FUNC_SMBUS_WORD_DATA))
+7 -1
drivers/base/regmap/regmap-ram.c
··· 71 71 return ERR_PTR(-ENOMEM); 72 72 73 73 data->written = kzalloc_objs(bool, config->max_register + 1); 74 - if (!data->written) 74 + if (!data->written) { 75 + kfree(data->read); 75 76 return ERR_PTR(-ENOMEM); 77 + } 76 78 77 79 map = __regmap_init(dev, &regmap_ram, data, config, 78 80 lock_key, lock_name); 81 + if (IS_ERR(map)) { 82 + kfree(data->read); 83 + kfree(data->written); 84 + } 79 85 80 86 return map; 81 87 }