linux-rtc.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Alexandre Belloni <alexandre.belloni@bootlin.com>
To: Bharadwaj Raju <bharadwaj.raju777@gmail.com>
Cc: linux-rtc@vger.kernel.org, shuah@kernel.org,
	linux-kernel@vger.kernel.org,
	linux-kernel-mentees@lists.linux.dev
Subject: Re: [PATCH] rtc: fix use of uninit struct in rtc_read_alarm_internal
Date: Mon, 17 Mar 2025 22:51:10 +0100	[thread overview]
Message-ID: <2025031721511050987ca2@mail.local> (raw)
In-Reply-To: <20250317183349.346399-1-bharadwaj.raju777@gmail.com>

On 18/03/2025 00:03:43+0530, Bharadwaj Raju wrote:
> The trace call invokes rtc_tm_to_time64 on a
> potentially uninitialized alarm->time. Move the
> trace call to the path where we do successfully
> initialize and read that struct.
> 
> This fixes a KMSAN warning.
> 
> Fixes: 29a1f599c0cc ("rtc: Add tracepoints for RTC system")
> 
> Signed-off-by: Bharadwaj Raju <bharadwaj.raju777@gmail.com>
> ---
>  drivers/rtc/interface.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/rtc/interface.c b/drivers/rtc/interface.c
> index aaf76406cd7d..82ba33bf478b 100644
> --- a/drivers/rtc/interface.c
> +++ b/drivers/rtc/interface.c
> @@ -201,11 +201,12 @@ static int rtc_read_alarm_internal(struct rtc_device *rtc,
>  		alarm->time.tm_yday = -1;
>  		alarm->time.tm_isdst = -1;
>  		err = rtc->ops->read_alarm(rtc->dev.parent, alarm);
> +		if (!err)
> +			trace_rtc_read_alarm(rtc_tm_to_time64(&alarm->time), err);
>  	}
>  
>  	mutex_unlock(&rtc->ops_lock);
>  
> -	trace_rtc_read_alarm(rtc_tm_to_time64(&alarm->time), err);

This removes the tracepoint when there is an error, rendering it les
useful.

Also, as discussed about a year ago, alarm-time being uninitialized is
not actually an issue as mktime64 can handle whatever is the input so
this will never cause any problem so this isn't really a fix.

I suggest the following:

---

From: Alexandre Belloni <alexandre.belloni@bootlin.com>
Subject: [PATCH] rtc: interface: silence KMSAN warning

KMSAN complains that alarm->time can be used uninitialized. Pass 0 to
trace_rtc_read_alarm in case it has not been set.

Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
---
 drivers/rtc/interface.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/rtc/interface.c b/drivers/rtc/interface.c
index aaf76406cd7d..dc741ba29fa3 100644
--- a/drivers/rtc/interface.c
+++ b/drivers/rtc/interface.c
@@ -205,7 +205,7 @@ static int rtc_read_alarm_internal(struct rtc_device *rtc,
 
 	mutex_unlock(&rtc->ops_lock);
 
-	trace_rtc_read_alarm(rtc_tm_to_time64(&alarm->time), err);
+	trace_rtc_read_alarm(err?0:rtc_tm_to_time64(&alarm->time), err);
 	return err;
 }
 
-- 
2.48.1
²


-- 
Alexandre Belloni, co-owner and COO, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com

  reply	other threads:[~2025-03-17 21:51 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-03-17 18:33 [PATCH] rtc: fix use of uninit struct in rtc_read_alarm_internal Bharadwaj Raju
2025-03-17 21:51 ` Alexandre Belloni [this message]
2025-03-29 14:29   ` Bharadwaj Raju
2025-04-08 14:44     ` Alexandre Belloni

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=2025031721511050987ca2@mail.local \
    --to=alexandre.belloni@bootlin.com \
    --cc=bharadwaj.raju777@gmail.com \
    --cc=linux-kernel-mentees@lists.linux.dev \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-rtc@vger.kernel.org \
    --cc=shuah@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).