Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit e08ec158 authored by Joy Chakraborty's avatar Joy Chakraborty Committed by Greg Kroah-Hartman
Browse files

rtc: cmos: Fix return value of nvmem callbacks



commit 1c184baccf0d5e2ef4cc1562261d0e48508a1c2b upstream.

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: 8b5b7958 ("rtc: cmos: use generic nvmem")
Cc: stable@vger.kernel.org
Signed-off-by: default avatarJoy Chakraborty <joychakr@google.com>
Reviewed-by: default avatarDan Carpenter <dan.carpenter@linaro.org>
Link: https://lore.kernel.org/r/20240612083635.1253039-1-joychakr@google.com


Signed-off-by: default avatarAlexandre Belloni <alexandre.belloni@bootlin.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 81a15d28
Loading
Loading
Loading
Loading
+4 −6
Original line number Diff line number Diff line
@@ -601,11 +601,10 @@ static int cmos_nvram_read(void *priv, unsigned int off, void *val,
			   size_t count)
{
	unsigned char *buf = val;
	int	retval;

	off += NVRAM_OFFSET;
	spin_lock_irq(&rtc_lock);
	for (retval = 0; count; count--, off++, retval++) {
	for (; count; count--, off++) {
		if (off < 128)
			*buf++ = CMOS_READ(off);
		else if (can_bank2)
@@ -615,7 +614,7 @@ static int cmos_nvram_read(void *priv, unsigned int off, void *val,
	}
	spin_unlock_irq(&rtc_lock);

	return retval;
	return count ? -EIO : 0;
}

static int cmos_nvram_write(void *priv, unsigned int off, void *val,
@@ -623,7 +622,6 @@ static int cmos_nvram_write(void *priv, unsigned int off, void *val,
{
	struct cmos_rtc	*cmos = priv;
	unsigned char	*buf = val;
	int		retval;

	/* NOTE:  on at least PCs and Ataris, the boot firmware uses a
	 * checksum on part of the NVRAM data.  That's currently ignored
@@ -632,7 +630,7 @@ static int cmos_nvram_write(void *priv, unsigned int off, void *val,
	 */
	off += NVRAM_OFFSET;
	spin_lock_irq(&rtc_lock);
	for (retval = 0; count; count--, off++, retval++) {
	for (; count; count--, off++) {
		/* don't trash RTC registers */
		if (off == cmos->day_alrm
				|| off == cmos->mon_alrm
@@ -647,7 +645,7 @@ static int cmos_nvram_write(void *priv, unsigned int off, void *val,
	}
	spin_unlock_irq(&rtc_lock);

	return retval;
	return count ? -EIO : 0;
}

/*----------------------------------------------------------------*/