From: Andy Shevchenko <andy.shevchenko@gmail.com>
To: Christian Marangi <ansuelsmth@gmail.com>
Cc: "Andy Shevchenko" <andriy.shevchenko@linux.intel.com>,
"Uwe Kleine-König" <ukleinek@kernel.org>,
linux-kernel@vger.kernel.org, linux-pwm@vger.kernel.org,
"Benjamin Larsson" <benjamin.larsson@genexis.eu>,
"AngeloGioacchino Del Regno"
<angelogioacchino.delregno@collabora.com>,
"Lorenzo Bianconi" <lorenzo@kernel.org>
Subject: Re: [PATCH v17] pwm: airoha: Add support for EN7581 SoC
Date: Fri, 27 Jun 2025 07:15:22 +0300 [thread overview]
Message-ID: <aF4a2tLzLDOYlw6T@surfacebook.localdomain> (raw)
In-Reply-To: <685dcf1b.050a0220.2cbe17.6342@mx.google.com>
Fri, Jun 27, 2025 at 12:52:06AM +0200, Christian Marangi kirjoitti:
> On Thu, Jun 26, 2025 at 04:54:41PM +0300, Andy Shevchenko wrote:
> > On Wed, Jun 25, 2025 at 09:49:01PM +0200, Christian Marangi wrote:
...
> > > + if (refcount_read(&pc->buckets[bucket].used) == 0) {
> > > + pc->buckets[bucket].period_ticks = period_ticks;
> > > + pc->buckets[bucket].duty_ticks = duty_ticks;
> > > + ret = airoha_pwm_apply_bucket_config(pc, bucket,
> > > + duty_ticks,
> > > + period_ticks);
> > > + if (ret)
> > > + return ret;
> > > +
> > > + refcount_set(&pc->buckets[bucket].used, 1);
> >
> > What happens if refcount is updated in between? This is wrong use of atomics.
> >
> > > + } else {
> > > + refcount_inc(&pc->buckets[bucket].used);
> >
> > Ditto.
> >
> > You probably wanted _inc_and_test() variant.
>
> The main problem is that adding macro for refcount and atomic is that
> normaly you expect to have parallel ASM code for it to have real aotmic
> OP. Anyway I think I solved it with a simple mutex.
>
> The usage of refcount here it's not really for atomic but for object
> tracking but refcount doesn't love to initialize from 0 and incremented
> so I have to use this _set and _inc thing.
Indeed, the main use of refcount is to start with 1, when object gets
initialised and free it on 0, hence if there are more users the count
goes up and drops when a user of the resource drops.
> > > + }
--
With Best Regards,
Andy Shevchenko
next prev parent reply other threads:[~2025-06-27 4:15 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-06-25 19:49 [PATCH v17] pwm: airoha: Add support for EN7581 SoC Christian Marangi
2025-06-26 13:54 ` Andy Shevchenko
2025-06-26 22:52 ` Christian Marangi
2025-06-27 4:15 ` Andy Shevchenko [this message]
2025-06-26 19:54 ` kernel test robot
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=aF4a2tLzLDOYlw6T@surfacebook.localdomain \
--to=andy.shevchenko@gmail.com \
--cc=andriy.shevchenko@linux.intel.com \
--cc=angelogioacchino.delregno@collabora.com \
--cc=ansuelsmth@gmail.com \
--cc=benjamin.larsson@genexis.eu \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pwm@vger.kernel.org \
--cc=lorenzo@kernel.org \
--cc=ukleinek@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