mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Rouven Czerwinski <rouven.czerwinski@linaro.org>
To: Alexandre Belloni <alexandre.belloni@bootlin.com>
Cc: "Jens Wiklander" <jens.wiklander@linaro.org>,
	"Sumit Garg" <sumit.garg@kernel.org>,
	"Olivia Mackall" <olivia@selenic.com>,
	"Herbert Xu" <herbert@gondor.apana.org.au>,
	"Clément Léger" <clement.leger@bootlin.com>,
	op-tee@lists.trustedfirmware.org, linux-kernel@vger.kernel.org,
	linux-crypto@vger.kernel.org, linux-rtc@vger.kernel.org
Subject: Re: [PATCH 3/3] rtc: optee: simplify OP-TEE context match
Date: Fri, 30 Jan 2026 16:03:37 +0100	[thread overview]
Message-ID: <e05ccdce1e82b42e837d104922eec1600cce579d.camel@linaro.org> (raw)
In-Reply-To: <202601291605277bc279f4@mail.local>

Hi Alexandre,

On Thu, 2026-01-29 at 17:05 +0100, Alexandre Belloni wrote:
> On 26/01/2026 11:11:26+0100, Rouven Czerwinski via B4 Relay wrote:
> > From: Rouven Czerwinski <rouven.czerwinski@linaro.org>
> > 
> > Simplify the TEE implementor ID match by returning the boolean
> > expression directly instead of going through an if/else.
> > 
> > Signed-off-by: Rouven Czerwinski <rouven.czerwinski@linaro.org>
> > ---
> >  drivers/rtc/rtc-optee.c | 5 +----
> >  1 file changed, 1 insertion(+), 4 deletions(-)
> > 
> > diff --git a/drivers/rtc/rtc-optee.c b/drivers/rtc/rtc-optee.c
> > index 184c6d142801..2f18be3de684 100644
> > --- a/drivers/rtc/rtc-optee.c
> > +++ b/drivers/rtc/rtc-optee.c
> > @@ -541,10 +541,7 @@ static int optee_rtc_read_info(struct device
> > *dev, struct rtc_device *rtc,
> >  
> >  static int optee_ctx_match(struct tee_ioctl_version_data *ver,
> > const void *data)
> >  {
> > -	if (ver->impl_id == TEE_IMPL_ID_OPTEE)
> > -		return 1;
> > -	else
> > -		return 0;
> > +	return (ver->impl_id == TEE_IMPL_ID_OPTEE);
> 
> I guess the correct way to do this would be:
> 
> return !!(ver->impl_id == TEE_IMPL_ID_OPTEE);

Could you explain why? If I read the standard correctly, an equality
operation always produces either 1 or 0, so there should be no need for
!! here like there is for bit flag comparisons, i.e. !!(flag &
SOME_FLAG_SET) to normalize to 1 or 0. Wondering if I am missing
something.

> But is this change actually generating better code?
> 
> Before:
> 
> static int optee_ctx_match(struct tee_ioctl_version_data *ver, const
> void *data)
> {
>         if (ver->impl_id == TEE_IMPL_ID_OPTEE)
>        0:       e5900000        ldr     r0, [r0]
>                 return 1;
>         else
>                 return 0;
> }
>        4:       e2400001        sub     r0, r0, #1
>        8:       e16f0f10        clz     r0, r0
>        c:       e1a002a0        lsr     r0, r0, #5
>       10:       e12fff1e        bx      lr
> 
> After:
> 
> static int optee_ctx_match(struct tee_ioctl_version_data *ver, const
> void *data)
> {
>         return !!(ver->impl_id == TEE_IMPL_ID_OPTEE);
>        0:       e5900000        ldr     r0, [r0]
> }
>        4:       e2400001        sub     r0, r0, #1
>        8:       e16f0f10        clz     r0, r0
>        c:       e1a002a0        lsr     r0, r0, #5
>       10:       e12fff1e        bx      lr
> 
> I'm in favor of keeping the current version.

I like the short version better, but I am also not very attached to
getting this in at all, I'll let the maintainers decide.

Thanks and best regards,
Rouven



      reply	other threads:[~2026-01-30 15:03 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-01-26 10:11 [PATCH 0/3] OP-TEE/OP-TEE drivers: simplify context matches Rouven Czerwinski via B4 Relay
2026-01-26 10:11 ` [PATCH 1/3] optee: simplify OP-TEE context match Rouven Czerwinski via B4 Relay
2026-02-10  5:22   ` Sumit Garg
2026-03-04  9:34     ` Jens Wiklander
2026-01-26 10:11 ` [PATCH 2/3] hwrng: optee - " Rouven Czerwinski via B4 Relay
2026-02-06 10:57   ` Herbert Xu
2026-01-26 10:11 ` [PATCH 3/3] rtc: optee: " Rouven Czerwinski via B4 Relay
2026-01-29 16:05   ` Alexandre Belloni
2026-01-30 15:03     ` Rouven Czerwinski [this message]

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=e05ccdce1e82b42e837d104922eec1600cce579d.camel@linaro.org \
    --to=rouven.czerwinski@linaro.org \
    --cc=alexandre.belloni@bootlin.com \
    --cc=clement.leger@bootlin.com \
    --cc=herbert@gondor.apana.org.au \
    --cc=jens.wiklander@linaro.org \
    --cc=linux-crypto@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-rtc@vger.kernel.org \
    --cc=olivia@selenic.com \
    --cc=op-tee@lists.trustedfirmware.org \
    --cc=sumit.garg@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

all inboxes | Powered by JetHome®