Re: [PATCH 2/3] PM: add sysfs attributes for additional suspend/resume metrics
From: Joshua Crofts
Date: Tue Nov 10 2026 - 13:52:23 EST
On Tue, 10 Nov 2026 12:29:11 -0500
Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx> wrote:
...
> > +static ssize_t runtime_resume_count_show(struct device *dev,
> > + struct device_attribute *attr,
> > + char *buf)
> > +{
> > + u64 count;
> > +
> > + spin_lock_irq(&dev->power.lock);
> > + count = dev->power.resume_count;
> > + spin_unlock_irq(&dev->power.lock);
>
> Why is a lock needed at all? The value isn't going to "smear", it will
> change right after the lock anyway.
On 64-bit systems an aligned u64 read is atomic, but on 32-bit systems it
gets split into two 32-bit loads. Without locking, the read can tear
between the upper and lower halves.
> And if you need one, why not a guard()?
Yeah, I realized this after sending the series out, nevertheless
Sashiko flagged some other stuff so I thought I'd fixup in v2.
Thanks!
--
Kind regards,
Joshua Crofts