Skip to content

Commit 8bf9865

Browse files
committed
Merge branch 'i2c/for-next' of git://git.kernel.org/pub/scm/linux/kernel/git/wsa/linux
Pull i2c fixes from Wolfram Sang: "This contains a 5.8 regression fix for the Designware driver, a register bitfield fix for the fsi driver, and a missing sanity check for the I2C core" * 'i2c/for-next' of git://git.kernel.org/pub/scm/linux/kernel/git/wsa/linux: i2c: core: check returned size of emulated smbus block read i2c: fsi: Fix the port number field in status register i2c: designware: Adjust bus speed independently of ACPI
2 parents 42afe7d + 40e0520 commit 8bf9865

File tree

6 files changed

+28
-13
lines changed

6 files changed

+28
-13
lines changed

drivers/i2c/busses/i2c-designware-common.c

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -286,10 +286,8 @@ int i2c_dw_acpi_configure(struct device *device)
286286
}
287287
EXPORT_SYMBOL_GPL(i2c_dw_acpi_configure);
288288

289-
void i2c_dw_acpi_adjust_bus_speed(struct device *device)
289+
static u32 i2c_dw_acpi_round_bus_speed(struct device *device)
290290
{
291-
struct dw_i2c_dev *dev = dev_get_drvdata(device);
292-
struct i2c_timings *t = &dev->timings;
293291
u32 acpi_speed;
294292
int i;
295293

@@ -300,9 +298,22 @@ void i2c_dw_acpi_adjust_bus_speed(struct device *device)
300298
*/
301299
for (i = 0; i < ARRAY_SIZE(supported_speeds); i++) {
302300
if (acpi_speed >= supported_speeds[i])
303-
break;
301+
return supported_speeds[i];
304302
}
305-
acpi_speed = i < ARRAY_SIZE(supported_speeds) ? supported_speeds[i] : 0;
303+
304+
return 0;
305+
}
306+
307+
#else /* CONFIG_ACPI */
308+
309+
static inline u32 i2c_dw_acpi_round_bus_speed(struct device *device) { return 0; }
310+
311+
#endif /* CONFIG_ACPI */
312+
313+
void i2c_dw_adjust_bus_speed(struct dw_i2c_dev *dev)
314+
{
315+
u32 acpi_speed = i2c_dw_acpi_round_bus_speed(dev->dev);
316+
struct i2c_timings *t = &dev->timings;
306317

307318
/*
308319
* Find bus speed from the "clock-frequency" device property, ACPI
@@ -315,9 +326,7 @@ void i2c_dw_acpi_adjust_bus_speed(struct device *device)
315326
else
316327
t->bus_freq_hz = I2C_MAX_FAST_MODE_FREQ;
317328
}
318-
EXPORT_SYMBOL_GPL(i2c_dw_acpi_adjust_bus_speed);
319-
320-
#endif /* CONFIG_ACPI */
329+
EXPORT_SYMBOL_GPL(i2c_dw_adjust_bus_speed);
321330

322331
u32 i2c_dw_scl_hcnt(u32 ic_clk, u32 tSYMBOL, u32 tf, int cond, int offset)
323332
{

drivers/i2c/busses/i2c-designware-core.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -361,11 +361,10 @@ static inline int i2c_dw_probe_lock_support(struct dw_i2c_dev *dev) { return 0;
361361
#endif
362362

363363
int i2c_dw_validate_speed(struct dw_i2c_dev *dev);
364+
void i2c_dw_adjust_bus_speed(struct dw_i2c_dev *dev);
364365

365366
#if IS_ENABLED(CONFIG_ACPI)
366367
int i2c_dw_acpi_configure(struct device *device);
367-
void i2c_dw_acpi_adjust_bus_speed(struct device *device);
368368
#else
369369
static inline int i2c_dw_acpi_configure(struct device *device) { return -ENODEV; }
370-
static inline void i2c_dw_acpi_adjust_bus_speed(struct device *device) {}
371370
#endif

drivers/i2c/busses/i2c-designware-pcidrv.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ static int i2c_dw_pci_probe(struct pci_dev *pdev,
240240
}
241241
}
242242

243-
i2c_dw_acpi_adjust_bus_speed(&pdev->dev);
243+
i2c_dw_adjust_bus_speed(dev);
244244

245245
if (has_acpi_companion(&pdev->dev))
246246
i2c_dw_acpi_configure(&pdev->dev);

drivers/i2c/busses/i2c-designware-platdrv.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ static int dw_i2c_plat_probe(struct platform_device *pdev)
228228
else
229229
i2c_parse_fw_timings(&pdev->dev, t, false);
230230

231-
i2c_dw_acpi_adjust_bus_speed(&pdev->dev);
231+
i2c_dw_adjust_bus_speed(dev);
232232

233233
if (pdev->dev.of_node)
234234
dw_i2c_of_configure(pdev);

drivers/i2c/busses/i2c-fsi.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@
9898
#define I2C_STAT_DAT_REQ BIT(25)
9999
#define I2C_STAT_CMD_COMP BIT(24)
100100
#define I2C_STAT_STOP_ERR BIT(23)
101-
#define I2C_STAT_MAX_PORT GENMASK(19, 16)
101+
#define I2C_STAT_MAX_PORT GENMASK(22, 16)
102102
#define I2C_STAT_ANY_INT BIT(15)
103103
#define I2C_STAT_SCL_IN BIT(11)
104104
#define I2C_STAT_SDA_IN BIT(10)

drivers/i2c/i2c-core-smbus.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -495,6 +495,13 @@ static s32 i2c_smbus_xfer_emulated(struct i2c_adapter *adapter, u16 addr,
495495
break;
496496
case I2C_SMBUS_BLOCK_DATA:
497497
case I2C_SMBUS_BLOCK_PROC_CALL:
498+
if (msg[1].buf[0] > I2C_SMBUS_BLOCK_MAX) {
499+
dev_err(&adapter->dev,
500+
"Invalid block size returned: %d\n",
501+
msg[1].buf[0]);
502+
status = -EPROTO;
503+
goto cleanup;
504+
}
498505
for (i = 0; i < msg[1].buf[0] + 1; i++)
499506
data->block[i] = msg[1].buf[i];
500507
break;

0 commit comments

Comments
 (0)