Skip to content

Commit f9ecc83

Browse files
Sakari Ailusbrgl
authored andcommitted
eeprom: at24: fix I2C device selection for runtime PM
The at24 driver creates dummy I2C devices to access offsets in the chip that are outside the area supported using a single I2C address. It is not meaningful to use runtime PM to such devices; the system firmware (ACPI) does not know about these devices nor runtime PM was enabled for them. Always use the real device instead of the dummy ones. Fixes: 98e8201 ("eeprom: at24: enable runtime pm support") Signed-off-by: Sakari Ailus <[email protected]> Tested-by: Sven Van Asbroeck on a 24AA16/24LC16B <[email protected]> [Bartosz: rebased on top of previous fixes for 4.15, tweaked the commit message] [Sven: fixed Bartosz's rebase] Signed-off-by: Sven Van Asbroeck <[email protected]> Signed-off-by: Bartosz Golaszewski <[email protected]>
1 parent ae64f9b commit f9ecc83

File tree

1 file changed

+10
-14
lines changed

1 file changed

+10
-14
lines changed

drivers/misc/eeprom/at24.c

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -562,7 +562,7 @@ static ssize_t at24_eeprom_write_i2c(struct at24_data *at24, const char *buf,
562562
static int at24_read(void *priv, unsigned int off, void *val, size_t count)
563563
{
564564
struct at24_data *at24 = priv;
565-
struct i2c_client *client;
565+
struct device *dev = &at24->client[0]->dev;
566566
char *buf = val;
567567
int ret;
568568

@@ -572,11 +572,9 @@ static int at24_read(void *priv, unsigned int off, void *val, size_t count)
572572
if (off + count > at24->chip.byte_len)
573573
return -EINVAL;
574574

575-
client = at24_translate_offset(at24, &off);
576-
577-
ret = pm_runtime_get_sync(&client->dev);
575+
ret = pm_runtime_get_sync(dev);
578576
if (ret < 0) {
579-
pm_runtime_put_noidle(&client->dev);
577+
pm_runtime_put_noidle(dev);
580578
return ret;
581579
}
582580

@@ -592,7 +590,7 @@ static int at24_read(void *priv, unsigned int off, void *val, size_t count)
592590
status = at24->read_func(at24, buf, off, count);
593591
if (status < 0) {
594592
mutex_unlock(&at24->lock);
595-
pm_runtime_put(&client->dev);
593+
pm_runtime_put(dev);
596594
return status;
597595
}
598596
buf += status;
@@ -602,15 +600,15 @@ static int at24_read(void *priv, unsigned int off, void *val, size_t count)
602600

603601
mutex_unlock(&at24->lock);
604602

605-
pm_runtime_put(&client->dev);
603+
pm_runtime_put(dev);
606604

607605
return 0;
608606
}
609607

610608
static int at24_write(void *priv, unsigned int off, void *val, size_t count)
611609
{
612610
struct at24_data *at24 = priv;
613-
struct i2c_client *client;
611+
struct device *dev = &at24->client[0]->dev;
614612
char *buf = val;
615613
int ret;
616614

@@ -620,11 +618,9 @@ static int at24_write(void *priv, unsigned int off, void *val, size_t count)
620618
if (off + count > at24->chip.byte_len)
621619
return -EINVAL;
622620

623-
client = at24_translate_offset(at24, &off);
624-
625-
ret = pm_runtime_get_sync(&client->dev);
621+
ret = pm_runtime_get_sync(dev);
626622
if (ret < 0) {
627-
pm_runtime_put_noidle(&client->dev);
623+
pm_runtime_put_noidle(dev);
628624
return ret;
629625
}
630626

@@ -640,7 +636,7 @@ static int at24_write(void *priv, unsigned int off, void *val, size_t count)
640636
status = at24->write_func(at24, buf, off, count);
641637
if (status < 0) {
642638
mutex_unlock(&at24->lock);
643-
pm_runtime_put(&client->dev);
639+
pm_runtime_put(dev);
644640
return status;
645641
}
646642
buf += status;
@@ -650,7 +646,7 @@ static int at24_write(void *priv, unsigned int off, void *val, size_t count)
650646

651647
mutex_unlock(&at24->lock);
652648

653-
pm_runtime_put(&client->dev);
649+
pm_runtime_put(dev);
654650

655651
return 0;
656652
}

0 commit comments

Comments
 (0)