[PATCH] i3c: dw: make struct dw_i3c_cmd smaller

Jisheng Zhang posted 1 patch 1 month, 2 weeks ago
drivers/i3c/master/dw-i3c-master.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
[PATCH] i3c: dw: make struct dw_i3c_cmd smaller
Posted by Jisheng Zhang 1 month, 2 weeks ago
The dw_i3c_cmd is dynamically allocated, make it smaller. For example
on 64bit platforms, we reduce the size from 48 bytes to 32 bytes.

Signed-off-by: Jisheng Zhang <jszhang@kernel.org>
---
 drivers/i3c/master/dw-i3c-master.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/i3c/master/dw-i3c-master.c b/drivers/i3c/master/dw-i3c-master.c
index 6ba84a97765f..d6f84f0f4c2d 100644
--- a/drivers/i3c/master/dw-i3c-master.c
+++ b/drivers/i3c/master/dw-i3c-master.c
@@ -247,10 +247,10 @@ struct dw_i3c_cmd {
 	u32 cmd_lo;
 	u32 cmd_hi;
 	u16 tx_len;
-	const void *tx_buf;
 	u16 rx_len;
-	void *rx_buf;
 	u8 error;
+	const void *tx_buf;
+	void *rx_buf;
 };
 
 struct dw_i3c_xfer {
-- 
2.51.0
Re: [PATCH] i3c: dw: make struct dw_i3c_cmd smaller
Posted by Alexandre Belloni 1 month, 1 week ago
On Thu, 13 Aug 2026 12:46:03 +0800, Jisheng Zhang wrote:
> The dw_i3c_cmd is dynamically allocated, make it smaller. For example
> on 64bit platforms, we reduce the size from 48 bytes to 32 bytes.

Applied, thanks!

[1/1] i3c: dw: make struct dw_i3c_cmd smaller
      https://git.kernel.org/i3c/c/9939e4cf593d

Best regards,

-- 
Alexandre Belloni, co-owner and COO, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
Re: [PATCH] i3c: dw: make struct dw_i3c_cmd smaller
Posted by Frank Li 1 month, 2 weeks ago
On Thu, Aug 13, 2026 at 12:46:03PM +0800, Jisheng Zhang wrote:
> The dw_i3c_cmd is dynamically allocated, make it smaller. For example
> on 64bit platforms, we reduce the size from 48 bytes to 32 bytes.
>
> Signed-off-by: Jisheng Zhang <jszhang@kernel.org>
> ---
>  drivers/i3c/master/dw-i3c-master.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/i3c/master/dw-i3c-master.c b/drivers/i3c/master/dw-i3c-master.c
> index 6ba84a97765f..d6f84f0f4c2d 100644
> --- a/drivers/i3c/master/dw-i3c-master.c
> +++ b/drivers/i3c/master/dw-i3c-master.c
> @@ -247,10 +247,10 @@ struct dw_i3c_cmd {
>  	u32 cmd_lo;
>  	u32 cmd_hi;
>  	u16 tx_len;
> -	const void *tx_buf;
>  	u16 rx_len;

only switch rx_len and tx_buf should be enough. otherwise there are data
pad after u8 error.

Frank

> -	void *rx_buf;
>  	u8 error;
> +	const void *tx_buf;
> +	void *rx_buf;
>  };
>
>  struct dw_i3c_xfer {
> --
> 2.51.0
>
Re: [PATCH] i3c: dw: make struct dw_i3c_cmd smaller
Posted by Jisheng Zhang 1 month, 2 weeks ago
On Thu, Aug 13, 2026 at 04:38:32PM -0400, Frank Li wrote:
> On Thu, Aug 13, 2026 at 12:46:03PM +0800, Jisheng Zhang wrote:
> > The dw_i3c_cmd is dynamically allocated, make it smaller. For example
> > on 64bit platforms, we reduce the size from 48 bytes to 32 bytes.
> >
> > Signed-off-by: Jisheng Zhang <jszhang@kernel.org>
> > ---
> >  drivers/i3c/master/dw-i3c-master.c | 4 ++--
> >  1 file changed, 2 insertions(+), 2 deletions(-)
> >
> > diff --git a/drivers/i3c/master/dw-i3c-master.c b/drivers/i3c/master/dw-i3c-master.c
> > index 6ba84a97765f..d6f84f0f4c2d 100644
> > --- a/drivers/i3c/master/dw-i3c-master.c
> > +++ b/drivers/i3c/master/dw-i3c-master.c
> > @@ -247,10 +247,10 @@ struct dw_i3c_cmd {
> >  	u32 cmd_lo;
> >  	u32 cmd_hi;
> >  	u16 tx_len;
> > -	const void *tx_buf;
> >  	u16 rx_len;
> 
> only switch rx_len and tx_buf should be enough. otherwise there are data
> pad after u8 error.

If we keep the error at the end of the struct, there's still padding
after the u8 error.
There's no big difference between current sol and only switch rx_len and
tx_buf on 32bit platforms. But on 64bit platforms, the current version
makes use of the pad to store the error, thus saves 8 byte more.

Thanks
> 
> Frank
> 
> > -	void *rx_buf;
> >  	u8 error;
> > +	const void *tx_buf;
> > +	void *rx_buf;
> >  };
> >
> >  struct dw_i3c_xfer {
> > --
> > 2.51.0
> >
Re: [PATCH] i3c: dw: make struct dw_i3c_cmd smaller
Posted by Frank Li 1 month, 2 weeks ago
On Fri, Aug 14, 2026 at 11:57:24AM +0800, Jisheng Zhang wrote:
> On Thu, Aug 13, 2026 at 04:38:32PM -0400, Frank Li wrote:
> > On Thu, Aug 13, 2026 at 12:46:03PM +0800, Jisheng Zhang wrote:
> > > The dw_i3c_cmd is dynamically allocated, make it smaller. For example
> > > on 64bit platforms, we reduce the size from 48 bytes to 32 bytes.
> > >
> > > Signed-off-by: Jisheng Zhang <jszhang@kernel.org>
> > > ---
> > >  drivers/i3c/master/dw-i3c-master.c | 4 ++--
> > >  1 file changed, 2 insertions(+), 2 deletions(-)
> > >
> > > diff --git a/drivers/i3c/master/dw-i3c-master.c b/drivers/i3c/master/dw-i3c-master.c
> > > index 6ba84a97765f..d6f84f0f4c2d 100644
> > > --- a/drivers/i3c/master/dw-i3c-master.c
> > > +++ b/drivers/i3c/master/dw-i3c-master.c
> > > @@ -247,10 +247,10 @@ struct dw_i3c_cmd {
> > >  	u32 cmd_lo;
> > >  	u32 cmd_hi;
> > >  	u16 tx_len;
> > > -	const void *tx_buf;
> > >  	u16 rx_len;
> >
> > only switch rx_len and tx_buf should be enough. otherwise there are data
> > pad after u8 error.
>
> If we keep the error at the end of the struct, there's still padding
> after the u8 error.
> There's no big difference between current sol and only switch rx_len and
> tx_buf on 32bit platforms. But on 64bit platforms, the current version
> makes use of the pad to store the error, thus saves 8 byte more.

Yes, I missed caculate.

Reviewed-by: Frank Li <Frank.Li@nxp.com>

>
> Thanks
> >
> > Frank
> >
> > > -	void *rx_buf;
> > >  	u8 error;
> > > +	const void *tx_buf;
> > > +	void *rx_buf;
> > >  };
> > >
> > >  struct dw_i3c_xfer {
> > > --
> > > 2.51.0
> > >