linux-mmc.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Bean Huo <beanhuo@iokpp.de>
To: Avri Altman <Avri.Altman@sandisk.com>,
	"ulf.hansson@linaro.org" <ulf.hansson@linaro.org>,
	"linux-mmc@vger.kernel.org" <linux-mmc@vger.kernel.org>,
	"jens.wiklander@linaro.org" <jens.wiklander@linaro.org>
Cc: Bean Huo <beanhuo@micron.com>
Subject: Re: [PATCH v1 2/2] mmc: core: Improve RPMB frame handling code
Date: Wed, 10 Sep 2025 21:23:59 +0200	[thread overview]
Message-ID: <f6e512e657bfa12ac88f2ae153edcad960dfb2c4.camel@iokpp.de> (raw)
In-Reply-To: <PH7PR16MB61967841097FC4DC0CA94330E50EA@PH7PR16MB6196.namprd16.prod.outlook.com>

On Wed, 2025-09-10 at 07:16 +0000, Avri Altman wrote:
> > From: Bean Huo <beanhuo@micron.com>
> > 
> > Simplify the switch statement by combining RPMB_PROGRAM_KEY and
> > RPMB_GET_WRITE_COUNTER
> > cases which have identical validation logic. Add RPMB_FRAME_SIZE macro
> > and replace all
> > sizeof(struct rpmb_frame) occurrences for better maintainability and
> > readability.
> > 
> > Signed-off-by: Bean Huo <beanhuo@micron.com>
> > ---
> >   drivers/mmc/core/block.c | 35 +++++++++++++++--------------------
> >   1 file changed, 15 insertions(+), 20 deletions(-)
> > 
> > diff --git a/drivers/mmc/core/block.c b/drivers/mmc/core/block.c
> > index dd6cffc0df72..7fe9e8cc1ce4 100644
> > --- a/drivers/mmc/core/block.c
> > +++ b/drivers/mmc/core/block.c
> > @@ -121,6 +121,8 @@ struct rpmb_frame {
> >   #define RPMB_READ_DATA         0x4    /* Read data from RPMB partition */
> >   #define RPMB_RESULT_READ       0x5    /* Read result request  (Internal) */
> > 
> > +#define RPMB_FRAME_SIZE        sizeof(struct rpmb_frame)
> Since you only check != and alignment, maybe you could further generalize it by using:
> #define CHECK_SIZE_NEQ(val) ((val) != sizeof(struct rpmb_frame))
> #define CHECK_SIZE_ALIGNED(val) IS_ALIGNED((val), sizeof(struct rpmb_frame))
> 
> >   static DEFINE_MUTEX(block_mutex);
> > 
> >   /*
> > @@ -2864,12 +2866,12 @@ static void set_idata(struct mmc_blk_ioc_data
> > *idata, u32 opcode,
> >           * The size of an RPMB frame must match what's expected by the
> >           * hardware.
> >           */
> > -       BUILD_BUG_ON(sizeof(struct rpmb_frame) != 512);
> > +       BUILD_BUG_ON(RPMB_FRAME_SIZE != 512);
> Maybe while at it change this to static_assert() ?
> 
> > 
> >          idata->ic.opcode = opcode;
> >          idata->ic.flags = MMC_RSP_R1 | MMC_CMD_ADTC;
> >          idata->ic.write_flag = write_flag;
> > -       idata->ic.blksz = sizeof(struct rpmb_frame);
> > +       idata->ic.blksz = RPMB_FRAME_SIZE;
> >          idata->ic.blocks = buf_bytes /  idata->ic.blksz;
> >          idata->buf = buf;
> >          idata->buf_bytes = buf_bytes;
> > @@ -2893,32 +2895,27 @@ static int mmc_route_rpmb_frames(struct device
> > *dev, u8 *req,
> >          if (IS_ERR(md->queue.card))
> >                  return PTR_ERR(md->queue.card);
> > 
> > -       if (req_len < sizeof(*frm))
> > +       if (req_len < RPMB_FRAME_SIZE)
> >                  return -EINVAL;
> > 
> >          req_type = be16_to_cpu(frm->req_resp);
> >          switch (req_type) {
> >          case RPMB_PROGRAM_KEY:
> > -               if (req_len != sizeof(struct rpmb_frame) ||
> > -                   resp_len != sizeof(struct rpmb_frame))
> > -                       return -EINVAL;
> > -               write = true;
> > -               break;
> >          case RPMB_GET_WRITE_COUNTER:
> > -               if (req_len != sizeof(struct rpmb_frame) ||
> > -                   resp_len != sizeof(struct rpmb_frame))
> > +               if (req_len != RPMB_FRAME_SIZE ||
> > +                   resp_len != RPMB_FRAME_SIZE)
> >                          return -EINVAL;
> > -               write = false;
> > +               write = (req_type == RPMB_PROGRAM_KEY);
> A little bit awkward?  Maybe leave this for now?

Avri, 

thank you for reviewing. I’ll incorporate your suggestions in the next version.

Kind regards,
Bean

      reply	other threads:[~2025-09-10 19:24 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-09-09 21:13 [PATCH v1 0/2] mmc: core: RPMB code improvements Bean Huo
2025-09-09 21:13 ` [PATCH v1 1/2] mmc: core: Fix variable shadowing in mmc_route_rpmb_frames() Bean Huo
2025-09-10  5:42   ` Avri Altman
2025-09-10  6:17     ` Jens Wiklander
2025-09-09 21:13 ` [PATCH v1 2/2] mmc: core: Improve RPMB frame handling code Bean Huo
2025-09-10  7:16   ` Avri Altman
2025-09-10 19:23     ` Bean Huo [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=f6e512e657bfa12ac88f2ae153edcad960dfb2c4.camel@iokpp.de \
    --to=beanhuo@iokpp.de \
    --cc=Avri.Altman@sandisk.com \
    --cc=beanhuo@micron.com \
    --cc=jens.wiklander@linaro.org \
    --cc=linux-mmc@vger.kernel.org \
    --cc=ulf.hansson@linaro.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;
as well as URLs for NNTP newsgroup(s).