* [PATCH 0/3] OP-TEE/OP-TEE drivers: simplify context matches
@ 2026-01-26 10:11 Rouven Czerwinski via B4 Relay
2026-01-26 10:11 ` [PATCH 1/3] optee: simplify OP-TEE context match Rouven Czerwinski via B4 Relay
` (2 more replies)
0 siblings, 3 replies; 9+ messages in thread
From: Rouven Czerwinski via B4 Relay @ 2026-01-26 10:11 UTC (permalink / raw)
To: Jens Wiklander, Sumit Garg, Olivia Mackall, Herbert Xu,
Clément Léger, Alexandre Belloni
Cc: op-tee, linux-kernel, linux-crypto, linux-rtc, Rouven Czerwinski
Both the OP-TEE core and some OP-TEE drivers use an if/else expression
to check a boolean which can instead be returned directly. Implement
this change.
---
Rouven Czerwinski (3):
optee: simplify OP-TEE context match
hwrng: optee - simplify OP-TEE context match
rtc: optee: simplify OP-TEE context match
drivers/char/hw_random/optee-rng.c | 5 +----
drivers/rtc/rtc-optee.c | 5 +----
drivers/tee/optee/device.c | 5 +----
3 files changed, 3 insertions(+), 12 deletions(-)
---
base-commit: 63804fed149a6750ffd28610c5c1c98cce6bd377
change-id: 20260126-optee-simplify-context-match-d5b3467bfacc
Best regards,
--
Rouven Czerwinski <rouven.czerwinski@linaro.org>
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH 1/3] optee: simplify OP-TEE context match
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 ` Rouven Czerwinski via B4 Relay
2026-02-10 5:22 ` Sumit Garg
2026-01-26 10:11 ` [PATCH 2/3] hwrng: optee - " Rouven Czerwinski via B4 Relay
2026-01-26 10:11 ` [PATCH 3/3] rtc: optee: " Rouven Czerwinski via B4 Relay
2 siblings, 1 reply; 9+ messages in thread
From: Rouven Czerwinski via B4 Relay @ 2026-01-26 10:11 UTC (permalink / raw)
To: Jens Wiklander, Sumit Garg, Olivia Mackall, Herbert Xu,
Clément Léger, Alexandre Belloni
Cc: op-tee, linux-kernel, linux-crypto, linux-rtc, Rouven Czerwinski
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/tee/optee/device.c | 5 +----
1 file changed, 1 insertion(+), 4 deletions(-)
diff --git a/drivers/tee/optee/device.c b/drivers/tee/optee/device.c
index 950b4661d5df..4c85b04d6004 100644
--- a/drivers/tee/optee/device.c
+++ b/drivers/tee/optee/device.c
@@ -13,10 +13,7 @@
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);
}
static int get_devices(struct tee_context *ctx, u32 session,
--
2.52.0
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH 2/3] hwrng: optee - simplify OP-TEE context match
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-01-26 10:11 ` 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
2 siblings, 1 reply; 9+ messages in thread
From: Rouven Czerwinski via B4 Relay @ 2026-01-26 10:11 UTC (permalink / raw)
To: Jens Wiklander, Sumit Garg, Olivia Mackall, Herbert Xu,
Clément Léger, Alexandre Belloni
Cc: op-tee, linux-kernel, linux-crypto, linux-rtc, Rouven Czerwinski
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/char/hw_random/optee-rng.c | 5 +----
1 file changed, 1 insertion(+), 4 deletions(-)
diff --git a/drivers/char/hw_random/optee-rng.c b/drivers/char/hw_random/optee-rng.c
index 96b5d546d136..1cb741a6d112 100644
--- a/drivers/char/hw_random/optee-rng.c
+++ b/drivers/char/hw_random/optee-rng.c
@@ -205,10 +205,7 @@ static int get_optee_rng_info(struct device *dev)
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);
}
static int optee_rng_probe(struct device *dev)
--
2.52.0
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH 3/3] rtc: optee: simplify OP-TEE context match
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-01-26 10:11 ` [PATCH 2/3] hwrng: optee - " Rouven Czerwinski via B4 Relay
@ 2026-01-26 10:11 ` Rouven Czerwinski via B4 Relay
2026-01-29 16:05 ` Alexandre Belloni
2 siblings, 1 reply; 9+ messages in thread
From: Rouven Czerwinski via B4 Relay @ 2026-01-26 10:11 UTC (permalink / raw)
To: Jens Wiklander, Sumit Garg, Olivia Mackall, Herbert Xu,
Clément Léger, Alexandre Belloni
Cc: op-tee, linux-kernel, linux-crypto, linux-rtc, Rouven Czerwinski
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);
}
static int optee_rtc_probe(struct device *dev)
--
2.52.0
^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [PATCH 3/3] rtc: optee: simplify OP-TEE context match
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
0 siblings, 1 reply; 9+ messages in thread
From: Alexandre Belloni @ 2026-01-29 16:05 UTC (permalink / raw)
To: rouven.czerwinski
Cc: Jens Wiklander, Sumit Garg, Olivia Mackall, Herbert Xu,
Clément Léger, op-tee, linux-kernel, linux-crypto,
linux-rtc
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);
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.
--
Alexandre Belloni, co-owner and COO, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH 3/3] rtc: optee: simplify OP-TEE context match
2026-01-29 16:05 ` Alexandre Belloni
@ 2026-01-30 15:03 ` Rouven Czerwinski
0 siblings, 0 replies; 9+ messages in thread
From: Rouven Czerwinski @ 2026-01-30 15:03 UTC (permalink / raw)
To: Alexandre Belloni
Cc: Jens Wiklander, Sumit Garg, Olivia Mackall, Herbert Xu,
Clément Léger, op-tee, linux-kernel, linux-crypto,
linux-rtc
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
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH 2/3] hwrng: optee - simplify OP-TEE context match
2026-01-26 10:11 ` [PATCH 2/3] hwrng: optee - " Rouven Czerwinski via B4 Relay
@ 2026-02-06 10:57 ` Herbert Xu
0 siblings, 0 replies; 9+ messages in thread
From: Herbert Xu @ 2026-02-06 10:57 UTC (permalink / raw)
To: rouven.czerwinski
Cc: Jens Wiklander, Sumit Garg, Olivia Mackall,
Clément Léger, Alexandre Belloni, op-tee, linux-kernel,
linux-crypto, linux-rtc
On Mon, Jan 26, 2026 at 11:11:25AM +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/char/hw_random/optee-rng.c | 5 +----
> 1 file changed, 1 insertion(+), 4 deletions(-)
Patch applied. Thanks.
--
Email: Herbert Xu <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH 1/3] optee: simplify OP-TEE context match
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
0 siblings, 1 reply; 9+ messages in thread
From: Sumit Garg @ 2026-02-10 5:22 UTC (permalink / raw)
To: rouven.czerwinski
Cc: Jens Wiklander, Olivia Mackall, Herbert Xu,
Clément Léger, Alexandre Belloni, op-tee, linux-kernel,
linux-crypto, linux-rtc
On Mon, Jan 26, 2026 at 11:11:24AM +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/tee/optee/device.c | 5 +----
> 1 file changed, 1 insertion(+), 4 deletions(-)
>
Reviewed-by: Sumit Garg <sumit.garg@oss.qualcomm.com>
-Sumit
> diff --git a/drivers/tee/optee/device.c b/drivers/tee/optee/device.c
> index 950b4661d5df..4c85b04d6004 100644
> --- a/drivers/tee/optee/device.c
> +++ b/drivers/tee/optee/device.c
> @@ -13,10 +13,7 @@
>
> 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);
> }
>
> static int get_devices(struct tee_context *ctx, u32 session,
>
> --
> 2.52.0
>
>
>
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH 1/3] optee: simplify OP-TEE context match
2026-02-10 5:22 ` Sumit Garg
@ 2026-03-04 9:34 ` Jens Wiklander
0 siblings, 0 replies; 9+ messages in thread
From: Jens Wiklander @ 2026-03-04 9:34 UTC (permalink / raw)
To: Sumit Garg
Cc: rouven.czerwinski, Olivia Mackall, Herbert Xu,
Clément Léger, Alexandre Belloni, op-tee, linux-kernel,
linux-crypto, linux-rtc
On Tue, Feb 10, 2026 at 6:22 AM Sumit Garg <sumit.garg@kernel.org> wrote:
>
> On Mon, Jan 26, 2026 at 11:11:24AM +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/tee/optee/device.c | 5 +----
> > 1 file changed, 1 insertion(+), 4 deletions(-)
> >
>
> Reviewed-by: Sumit Garg <sumit.garg@oss.qualcomm.com>
I'm picking up this.
Thanks,
Jens
>
> -Sumit
>
> > diff --git a/drivers/tee/optee/device.c b/drivers/tee/optee/device.c
> > index 950b4661d5df..4c85b04d6004 100644
> > --- a/drivers/tee/optee/device.c
> > +++ b/drivers/tee/optee/device.c
> > @@ -13,10 +13,7 @@
> >
> > 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);
> > }
> >
> > static int get_devices(struct tee_context *ctx, u32 session,
> >
> > --
> > 2.52.0
> >
> >
> >
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2026-03-04 9:34 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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 is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox