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 E4E021A76A4; Thu, 15 Aug 2024 14:16:34 +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=1723731395; cv=none; b=MnjeTImd5NSPuAiOHWy/0CLLIxLpa9mhpilkr3/Qstcp/s3zriXlFpTJe26LeHnpoK2OTMJaKmyLka/hLYkCQUbZoqm2PtMzZrDHtvN5uJghIdVTG/LsuqUuCFiZFY5BHGW1Gh90ZwPzv84RRAuZw8rKmBSHiBTWieVE104KtTI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723731395; c=relaxed/simple; bh=3b6GbRCGtzqm6kpBSUzEtlgY3QDM6atXfIqNYzcCdWo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=okhzvB8GbxsW7jlZ59BKJEeJAJC8zocQBNqlCL6+8WmpuEQ3JJWetD+1+pSI1SkrrSdRzO2miCudjOVkbM6Y3WpZorBaBFHVYKj84ryyBjnX+7/RjmT+gzp03PdSLNrJzRfz3VU8jhQNLeHCZqWORaJ+ipz0olHTAruMLbqim8A= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=LSf1NrZr; 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="LSf1NrZr" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 715A8C32786; Thu, 15 Aug 2024 14:16:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1723731394; bh=3b6GbRCGtzqm6kpBSUzEtlgY3QDM6atXfIqNYzcCdWo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=LSf1NrZryZTN2FaPHvx0kiWSgh4sdhnLknd3s6xmnZv5BUHj+0UVGII3sreNYCRJN eetlFXihXYhFPnh/e2WKxg+9twQzR/SPt3i7UaZf7zfZYjDT379hmmoEZwE2YryfGk GyLOWlm8GCtAbkjrn6TmyLcsaiQBwNQ+D7JbQ8u8= 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.4 115/259] rtc: cmos: Fix return value of nvmem callbacks Date: Thu, 15 Aug 2024 15:24:08 +0200 Message-ID: <20240815131907.240626447@linuxfoundation.org> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240815131902.779125794@linuxfoundation.org> References: <20240815131902.779125794@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.4-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 @@ -597,11 +597,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) @@ -611,7 +610,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, @@ -619,7 +618,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 @@ -628,7 +626,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 @@ -643,7 +641,7 @@ static int cmos_nvram_write(void *priv, } spin_unlock_irq(&rtc_lock); - return retval; + return count ? -EIO : 0; } /*----------------------------------------------------------------*/