Skip to content

Commit 21f35d2

Browse files
committed
Merge branch 'i2c/for-current' of git://git.kernel.org/pub/scm/linux/kernel/git/wsa/linux
Pull i2c fixes from Wolfram Sang: "Fix the regression with AMD GPU suspend by reverting the handling of bus regulators in the I2C core. Also, there is a fix for the MPC driver to prevent an out-of-bound-access" * 'i2c/for-current' of git://git.kernel.org/pub/scm/linux/kernel/git/wsa/linux: Revert "i2c: core: support bus regulator controlling in adapter" i2c: mpc: Avoid out of bounds memory access
2 parents d445d64 + a19f75d commit 21f35d2

File tree

2 files changed

+9
-101
lines changed

2 files changed

+9
-101
lines changed

drivers/i2c/busses/i2c-mpc.c

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -492,7 +492,7 @@ static void mpc_i2c_finish(struct mpc_i2c *i2c, int rc)
492492

493493
static void mpc_i2c_do_action(struct mpc_i2c *i2c)
494494
{
495-
struct i2c_msg *msg = &i2c->msgs[i2c->curr_msg];
495+
struct i2c_msg *msg = NULL;
496496
int dir = 0;
497497
int recv_len = 0;
498498
u8 byte;
@@ -501,10 +501,13 @@ static void mpc_i2c_do_action(struct mpc_i2c *i2c)
501501

502502
i2c->cntl_bits &= ~(CCR_RSTA | CCR_MTX | CCR_TXAK);
503503

504-
if (msg->flags & I2C_M_RD)
505-
dir = 1;
506-
if (msg->flags & I2C_M_RECV_LEN)
507-
recv_len = 1;
504+
if (i2c->action != MPC_I2C_ACTION_STOP) {
505+
msg = &i2c->msgs[i2c->curr_msg];
506+
if (msg->flags & I2C_M_RD)
507+
dir = 1;
508+
if (msg->flags & I2C_M_RECV_LEN)
509+
recv_len = 1;
510+
}
508511

509512
switch (i2c->action) {
510513
case MPC_I2C_ACTION_RESTART:
@@ -581,7 +584,7 @@ static void mpc_i2c_do_action(struct mpc_i2c *i2c)
581584
break;
582585
}
583586

584-
if (msg->len == i2c->byte_posn) {
587+
if (msg && msg->len == i2c->byte_posn) {
585588
i2c->curr_msg++;
586589
i2c->byte_posn = 0;
587590

drivers/i2c/i2c-core-base.c

Lines changed: 0 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -466,14 +466,12 @@ static int i2c_smbus_host_notify_to_irq(const struct i2c_client *client)
466466
static int i2c_device_probe(struct device *dev)
467467
{
468468
struct i2c_client *client = i2c_verify_client(dev);
469-
struct i2c_adapter *adap;
470469
struct i2c_driver *driver;
471470
int status;
472471

473472
if (!client)
474473
return 0;
475474

476-
adap = client->adapter;
477475
client->irq = client->init_irq;
478476

479477
if (!client->irq) {
@@ -539,14 +537,6 @@ static int i2c_device_probe(struct device *dev)
539537

540538
dev_dbg(dev, "probe\n");
541539

542-
if (adap->bus_regulator) {
543-
status = regulator_enable(adap->bus_regulator);
544-
if (status < 0) {
545-
dev_err(&adap->dev, "Failed to enable bus regulator\n");
546-
goto err_clear_wakeup_irq;
547-
}
548-
}
549-
550540
status = of_clk_set_defaults(dev->of_node, false);
551541
if (status < 0)
552542
goto err_clear_wakeup_irq;
@@ -605,10 +595,8 @@ static int i2c_device_probe(struct device *dev)
605595
static void i2c_device_remove(struct device *dev)
606596
{
607597
struct i2c_client *client = to_i2c_client(dev);
608-
struct i2c_adapter *adap;
609598
struct i2c_driver *driver;
610599

611-
adap = client->adapter;
612600
driver = to_i2c_driver(dev->driver);
613601
if (driver->remove) {
614602
int status;
@@ -623,8 +611,6 @@ static void i2c_device_remove(struct device *dev)
623611
devres_release_group(&client->dev, client->devres_group_id);
624612

625613
dev_pm_domain_detach(&client->dev, !i2c_acpi_waive_d0_probe(dev));
626-
if (!pm_runtime_status_suspended(&client->dev) && adap->bus_regulator)
627-
regulator_disable(adap->bus_regulator);
628614

629615
dev_pm_clear_wake_irq(&client->dev);
630616
device_init_wakeup(&client->dev, false);
@@ -634,86 +620,6 @@ static void i2c_device_remove(struct device *dev)
634620
pm_runtime_put(&client->adapter->dev);
635621
}
636622

637-
#ifdef CONFIG_PM_SLEEP
638-
static int i2c_resume_early(struct device *dev)
639-
{
640-
struct i2c_client *client = i2c_verify_client(dev);
641-
int err;
642-
643-
if (!client)
644-
return 0;
645-
646-
if (pm_runtime_status_suspended(&client->dev) &&
647-
client->adapter->bus_regulator) {
648-
err = regulator_enable(client->adapter->bus_regulator);
649-
if (err)
650-
return err;
651-
}
652-
653-
return pm_generic_resume_early(&client->dev);
654-
}
655-
656-
static int i2c_suspend_late(struct device *dev)
657-
{
658-
struct i2c_client *client = i2c_verify_client(dev);
659-
int err;
660-
661-
if (!client)
662-
return 0;
663-
664-
err = pm_generic_suspend_late(&client->dev);
665-
if (err)
666-
return err;
667-
668-
if (!pm_runtime_status_suspended(&client->dev) &&
669-
client->adapter->bus_regulator)
670-
return regulator_disable(client->adapter->bus_regulator);
671-
672-
return 0;
673-
}
674-
#endif
675-
676-
#ifdef CONFIG_PM
677-
static int i2c_runtime_resume(struct device *dev)
678-
{
679-
struct i2c_client *client = i2c_verify_client(dev);
680-
int err;
681-
682-
if (!client)
683-
return 0;
684-
685-
if (client->adapter->bus_regulator) {
686-
err = regulator_enable(client->adapter->bus_regulator);
687-
if (err)
688-
return err;
689-
}
690-
691-
return pm_generic_runtime_resume(&client->dev);
692-
}
693-
694-
static int i2c_runtime_suspend(struct device *dev)
695-
{
696-
struct i2c_client *client = i2c_verify_client(dev);
697-
int err;
698-
699-
if (!client)
700-
return 0;
701-
702-
err = pm_generic_runtime_suspend(&client->dev);
703-
if (err)
704-
return err;
705-
706-
if (client->adapter->bus_regulator)
707-
return regulator_disable(client->adapter->bus_regulator);
708-
return 0;
709-
}
710-
#endif
711-
712-
static const struct dev_pm_ops i2c_device_pm = {
713-
SET_LATE_SYSTEM_SLEEP_PM_OPS(i2c_suspend_late, i2c_resume_early)
714-
SET_RUNTIME_PM_OPS(i2c_runtime_suspend, i2c_runtime_resume, NULL)
715-
};
716-
717623
static void i2c_device_shutdown(struct device *dev)
718624
{
719625
struct i2c_client *client = i2c_verify_client(dev);
@@ -773,7 +679,6 @@ struct bus_type i2c_bus_type = {
773679
.probe = i2c_device_probe,
774680
.remove = i2c_device_remove,
775681
.shutdown = i2c_device_shutdown,
776-
.pm = &i2c_device_pm,
777682
};
778683
EXPORT_SYMBOL_GPL(i2c_bus_type);
779684

0 commit comments

Comments
 (0)