Skip to content

Commit 3149a9c

Browse files
claudiubezneaAndi Shyti
authored andcommitted
i2c: riic: Use pm_runtime_resume_and_get()
pm_runtime_get_sync() may return with error. In case it returns with error dev->power.usage_count needs to be decremented. pm_runtime_resume_and_get() takes care of this. Thus use it. Reviewed-by: Wolfram Sang <[email protected]> Signed-off-by: Claudiu Beznea <[email protected]> Signed-off-by: Andi Shyti <[email protected]>
1 parent a1ecb04 commit 3149a9c

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

drivers/i2c/busses/i2c-riic.c

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -133,10 +133,12 @@ static int riic_xfer(struct i2c_adapter *adap, struct i2c_msg msgs[], int num)
133133
struct riic_dev *riic = i2c_get_adapdata(adap);
134134
struct device *dev = adap->dev.parent;
135135
unsigned long time_left;
136-
int i;
136+
int i, ret;
137137
u8 start_bit;
138138

139-
pm_runtime_get_sync(dev);
139+
ret = pm_runtime_resume_and_get(dev);
140+
if (ret)
141+
return ret;
140142

141143
if (riic_readb(riic, RIIC_ICCR2) & ICCR2_BBSY) {
142144
riic->err = -EBUSY;
@@ -301,6 +303,7 @@ static const struct i2c_algorithm riic_algo = {
301303

302304
static int riic_init_hw(struct riic_dev *riic, struct i2c_timings *t)
303305
{
306+
int ret;
304307
unsigned long rate;
305308
int total_ticks, cks, brl, brh;
306309
struct device *dev = riic->adapter.dev.parent;
@@ -379,7 +382,9 @@ static int riic_init_hw(struct riic_dev *riic, struct i2c_timings *t)
379382
t->scl_fall_ns / (1000000000 / rate),
380383
t->scl_rise_ns / (1000000000 / rate), cks, brl, brh);
381384

382-
pm_runtime_get_sync(dev);
385+
ret = pm_runtime_resume_and_get(dev);
386+
if (ret)
387+
return ret;
383388

384389
/* Changing the order of accessing IICRST and ICE may break things! */
385390
riic_writeb(riic, ICCR1_IICRST | ICCR1_SOWP, RIIC_ICCR1);
@@ -498,10 +503,13 @@ static void riic_i2c_remove(struct platform_device *pdev)
498503
{
499504
struct riic_dev *riic = platform_get_drvdata(pdev);
500505
struct device *dev = &pdev->dev;
506+
int ret;
501507

502-
pm_runtime_get_sync(dev);
503-
riic_writeb(riic, 0, RIIC_ICIER);
504-
pm_runtime_put(dev);
508+
ret = pm_runtime_resume_and_get(dev);
509+
if (!ret) {
510+
riic_writeb(riic, 0, RIIC_ICIER);
511+
pm_runtime_put(dev);
512+
}
505513
i2c_del_adapter(&riic->adapter);
506514
pm_runtime_disable(dev);
507515
}

0 commit comments

Comments
 (0)