Skip to content

Commit 1c184ba

Browse files
Joy Chakrabortyalexandrebelloni
authored andcommitted
rtc: cmos: Fix return value of nvmem callbacks
Read/write callbacks registered with nvmem core expect 0 to be returned on success and a negative value to be returned on failure. cmos_nvram_read()/cmos_nvram_write() currently return the number of bytes read or written, fix to return 0 on success and -EIO incase number of bytes requested was not read or written. Fixes: 8b5b795 ("rtc: cmos: use generic nvmem") Cc: [email protected] Signed-off-by: Joy Chakraborty <[email protected]> Reviewed-by: Dan Carpenter <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Alexandre Belloni <[email protected]>
1 parent 70f1ae5 commit 1c184ba

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

drivers/rtc/rtc-cmos.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -643,11 +643,10 @@ static int cmos_nvram_read(void *priv, unsigned int off, void *val,
643643
size_t count)
644644
{
645645
unsigned char *buf = val;
646-
int retval;
647646

648647
off += NVRAM_OFFSET;
649648
spin_lock_irq(&rtc_lock);
650-
for (retval = 0; count; count--, off++, retval++) {
649+
for (; count; count--, off++) {
651650
if (off < 128)
652651
*buf++ = CMOS_READ(off);
653652
else if (can_bank2)
@@ -657,15 +656,14 @@ static int cmos_nvram_read(void *priv, unsigned int off, void *val,
657656
}
658657
spin_unlock_irq(&rtc_lock);
659658

660-
return retval;
659+
return count ? -EIO : 0;
661660
}
662661

663662
static int cmos_nvram_write(void *priv, unsigned int off, void *val,
664663
size_t count)
665664
{
666665
struct cmos_rtc *cmos = priv;
667666
unsigned char *buf = val;
668-
int retval;
669667

670668
/* NOTE: on at least PCs and Ataris, the boot firmware uses a
671669
* checksum on part of the NVRAM data. That's currently ignored
@@ -674,7 +672,7 @@ static int cmos_nvram_write(void *priv, unsigned int off, void *val,
674672
*/
675673
off += NVRAM_OFFSET;
676674
spin_lock_irq(&rtc_lock);
677-
for (retval = 0; count; count--, off++, retval++) {
675+
for (; count; count--, off++) {
678676
/* don't trash RTC registers */
679677
if (off == cmos->day_alrm
680678
|| off == cmos->mon_alrm
@@ -689,7 +687,7 @@ static int cmos_nvram_write(void *priv, unsigned int off, void *val,
689687
}
690688
spin_unlock_irq(&rtc_lock);
691689

692-
return retval;
690+
return count ? -EIO : 0;
693691
}
694692

695693
/*----------------------------------------------------------------*/

0 commit comments

Comments
 (0)