[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <aWoBgt66shtVTovl@sumit-xelite>
Date: Fri, 16 Jan 2026 14:44:42 +0530
From: Sumit Garg <sumit.garg@...nel.org>
To: Colin King <coking@...dia.com>
Cc: ryan foster <foster.ryan.r@...il.com>,
Jens Wiklander <jens.wiklander@...aro.org>,
"op-tee@...ts.trustedfirmware.org" <op-tee@...ts.trustedfirmware.org>,
"kernel-janitors@...r.kernel.org" <kernel-janitors@...r.kernel.org>,
"linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>
Subject: Re: [PATCH][next] optee: make read-only array attr static const
On Mon, Jan 12, 2026 at 03:24:49PM +0000, Colin King wrote:
> I added this change for several reasons, it's read-only so making it const is always sensible. Making it static means we don't get the compiler to generate object code that stores the array on the stack (each time it's called) and then index into it, instead the data is put into a read-only data section at compile timne and the object code just fetched data from this array.
>
> Basically, if it's read-only it's good to make it const and it's not in an __init section then you may as well make it static const. It's scoped inside the function, even though it's in the data section.
>
That's fair. I don't have a strict preference here. Feel free to add:
Reviewed-by: Sumit Garg <sumit.garg@....qualcomm.com>
-Sumit
>
> ________________________________
> From: ryan foster <foster.ryan.r@...il.com>
> Sent: 12 January 2026 14:46
> To: Sumit Garg <sumit.garg@...nel.org>
> Cc: Colin King <coking@...dia.com>; Jens Wiklander <jens.wiklander@...aro.org>; op-tee@...ts.trustedfirmware.org <op-tee@...ts.trustedfirmware.org>; kernel-janitors@...r.kernel.org <kernel-janitors@...r.kernel.org>; linux-kernel@...r.kernel.org <linux-kernel@...r.kernel.org>
> Subject: Re: [PATCH][next] optee: make read-only array attr static const
>
> This looks like a micro-optimization, const makes the lookup array
> explicitly immutable, and static keeps it out of the stack frame,
> avoiding per-call initialization.
>
> Is there a style preference for read only lookup arrays here, e.g.
> Should these variables remain local but not static, or should they be
> moved to file scope static const?
>
> On Mon, Jan 12, 2026 at 3:26 AM Sumit Garg <sumit.garg@...nel.org> wrote:
> >
> > On Fri, Jan 09, 2026 at 03:44:42PM +0000, Colin Ian King wrote:
> > > Don't populate the read-only array attr on the stack at run
> > > time, instead make it static const.
> >
> > Is there any value add to do this? AFAIK, the static local variables
> > aren't preffered.
> >
> > -Sumit
> >
> > >
> > > Signed-off-by: Colin Ian King <coking@...dia.com>
> > > ---
> > > drivers/tee/optee/rpc.c | 2 +-
> > > 1 file changed, 1 insertion(+), 1 deletion(-)
> > >
> > > diff --git a/drivers/tee/optee/rpc.c b/drivers/tee/optee/rpc.c
> > > index 97fc5b14db0c..1758eb7e6e8b 100644
> > > --- a/drivers/tee/optee/rpc.c
> > > +++ b/drivers/tee/optee/rpc.c
> > > @@ -43,7 +43,7 @@ static void handle_rpc_func_cmd_i2c_transfer(struct tee_context *ctx,
> > > struct i2c_msg msg = { };
> > > size_t i;
> > > int ret = -EOPNOTSUPP;
> > > - u8 attr[] = {
> > > + static const u8 attr[] = {
> > > TEE_IOCTL_PARAM_ATTR_TYPE_VALUE_INPUT,
> > > TEE_IOCTL_PARAM_ATTR_TYPE_VALUE_INPUT,
> > > TEE_IOCTL_PARAM_ATTR_TYPE_MEMREF_INOUT,
> > > --
> > > 2.51.0
> > >
> >
Powered by blists - more mailing lists