From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7120C1494C5; Thu, 15 Aug 2024 13:50:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723729836; cv=none; b=AvD5Gjhpixs1yEs+QEZuCqZWtuYquGVdKKitJ8ioEFpAnwRnBvmsDglw/A6NsQGm+ZML9iyo0ZAxJJ8DTlvjT/Mv29eEi0+JEOYHUBj0nwR4EOmO2f3BcLGQHxHoMPcgQdI2iWQZhvYE3btH1ctCcz7IGGcpmVRfM/TMNjFR2Uw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723729836; c=relaxed/simple; bh=NSb7/KQ8GNXX0N27hwABiDh2ItSzBeXr/+y8+D1z49U=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=fGZ+Ql+2USw+7XjwZE67HeQKwM57sN6yXGrEVUPYOWafu94RU3ABe0ML6xOdSioRjp5a6h4fLHWcxTb0SGya/Dv2+ALPY+2hBwNtci1DSr2Wv9fseQL1xbFI3BfJMuze1K235kriks4Xc2OBWLuSQ1BE3T6dfuUauCC01Wukfgg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=ZX2fpiNy; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="ZX2fpiNy" Received: by smtp.kernel.org (Postfix) with ESMTPSA id EB0CCC32786; Thu, 15 Aug 2024 13:50:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1723729836; bh=NSb7/KQ8GNXX0N27hwABiDh2ItSzBeXr/+y8+D1z49U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ZX2fpiNyLcIpx4Lq8uBVG137i+iR2SauPP0Oz1zpBqh7UE1Hx1T8tiIvO005Uirfy HyyUk08bvmTUDozkAPN4mqQCGtQ+Fe5z2bGECrSQP9ZdkARe6Lh4z8YHHKpKW2IKS9 0IQcwj+4C3VHR/f4p9hHaUldgRgJ2qVjeBXcX4w4= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Joy Chakraborty , Dan Carpenter , Alexandre Belloni Subject: [PATCH 5.15 222/484] rtc: cmos: Fix return value of nvmem callbacks Date: Thu, 15 Aug 2024 15:21:20 +0200 Message-ID: <20240815131949.986881252@linuxfoundation.org> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240815131941.255804951@linuxfoundation.org> References: <20240815131941.255804951@linuxfoundation.org> User-Agent: quilt/0.67 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 5.15-stable review patch. If anyone has any objections, please let me know. ------------------ From: Joy Chakraborty 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: 8b5b7958fd1c ("rtc: cmos: use generic nvmem") Cc: stable@vger.kernel.org Signed-off-by: Joy Chakraborty Reviewed-by: Dan Carpenter Link: https://lore.kernel.org/r/20240612083635.1253039-1-joychakr@google.com Signed-off-by: Alexandre Belloni Signed-off-by: Greg Kroah-Hartman --- drivers/rtc/rtc-cmos.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) --- a/drivers/rtc/rtc-cmos.c +++ b/drivers/rtc/rtc-cmos.c @@ -643,11 +643,10 @@ static int cmos_nvram_read(void *priv, u 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) @@ -657,7 +656,7 @@ static int cmos_nvram_read(void *priv, u } spin_unlock_irq(&rtc_lock); - return retval; + return count ? -EIO : 0; } static int cmos_nvram_write(void *priv, unsigned int off, void *val, @@ -665,7 +664,6 @@ static int cmos_nvram_write(void *priv, { 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 @@ -674,7 +672,7 @@ static int cmos_nvram_write(void *priv, */ 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 @@ -689,7 +687,7 @@ static int cmos_nvram_write(void *priv, } spin_unlock_irq(&rtc_lock); - return retval; + return count ? -EIO : 0; } /*----------------------------------------------------------------*/