RE: [EXT] Re: [PATCH] hwrng: cn10k: Add extended trng register support

From: Bharat Bhushan
Date: Wed May 24 2023 - 07:57:35 EST




> -----Original Message-----
> From: Herbert Xu <herbert@xxxxxxxxxxxxxxxxxxx>
> Sent: Wednesday, May 24, 2023 3:26 PM
> To: Bharat Bhushan <bbhushan2@xxxxxxxxxxx>
> Cc: olivia@xxxxxxxxxxx; Jason@xxxxxxxxx; linux-crypto@xxxxxxxxxxxxxxx; linux-
> kernel@xxxxxxxxxxxxxxx; Sunil Kovvuri Goutham <sgoutham@xxxxxxxxxxx>
> Subject: [EXT] Re: [PATCH] hwrng: cn10k: Add extended trng register support
>
> External Email
>
> ----------------------------------------------------------------------
> On Thu, May 18, 2023 at 12:17:34PM +0530, Bharat Bhushan wrote:
> >
> > -static void cn10k_read_trng(struct cn10k_rng *rng, u64 *value)
> > +static size_t cn10k_read_trng(struct cn10k_rng *rng, u64 *value)
>
> Since the return value is either 0 or 8, why did you pick size_t as the return value?

This function returns number of valid bytes available in "value". 0 means no valid data. size_t is definitely wrong.
I think I will make this function to return bool, true when data is valid and false when data is not valid.

Thanks
-Bharat

>
> > {
> > + u16 retry_count = 0;
> > u64 upper, lower;
> > + u64 status;
> > +
> > + if (rng->extended_trng_regs) {
> > + do {
> > + *value = readq(rng->reg_base + RNM_PF_TRNG_DAT);
> > + if (*value)
> > + return 8;
> > + status = readq(rng->reg_base + RNM_PF_TRNG_RES);
> > + if (!status && (retry_count++ > 0x1000))
> > + return 0;
> > + } while (!status);
> > + }
> >
> > *value = readq(rng->reg_base + RNM_PF_RANDOM);
> >
> > @@ -82,6 +130,7 @@ static void cn10k_read_trng(struct cn10k_rng *rng,
> > u64 *value)
> >
> > *value = (upper & 0xFFFFFFFF00000000) | (lower & 0xFFFFFFFF);
> > }
> > + return 8;
> > }
> >
> > static int cn10k_rng_read(struct hwrng *hwrng, void *data, @@ -100,7
> > +149,9 @@ static int cn10k_rng_read(struct hwrng *hwrng, void *data,
> > size = max;
> >
> > while (size >= 8) {
> > - cn10k_read_trng(rng, &value);
> > + err = cn10k_read_trng(rng, &value);
> > + if (!err)
> > + goto out;
>
> It appears that err is either 8 or 0, so it's not really an error.
> Could you plesae use a more meaningful name for this variable?
>
> Cheers,
> --
> Email: Herbert Xu <herbert@xxxxxxxxxxxxxxxxxxx> Home Page:
> https://urldefense.proofpoint.com/v2/url?u=http-3A__gondor.apana.org.au_-
> 7Eherbert_&d=DwIBAg&c=nKjWec2b6R0mOyPaz7xtfQ&r=PAAlWswPe7d8gHlGb
> CLmy2YezyK7O3Hv_t2heGnouBw&m=Ya8SJ6OhypttG2itpa39dd7kXwEXGgbUOJ2
> Hqi95w7MetfxqRKKFX7aluHaLZpoc&s=pnRAp3oSzsNrbEAHZdLM6Eb9M4tDMxEd
> WLzANKejHwU&e=
> PGP Key: https://urldefense.proofpoint.com/v2/url?u=http-
> 3A__gondor.apana.org.au_-
> 7Eherbert_pubkey.txt&d=DwIBAg&c=nKjWec2b6R0mOyPaz7xtfQ&r=PAAlWswP
> e7d8gHlGbCLmy2YezyK7O3Hv_t2heGnouBw&m=Ya8SJ6OhypttG2itpa39dd7kXwE
> XGgbUOJ2Hqi95w7MetfxqRKKFX7aluHaLZpoc&s=pLpT-
> xdKvVvCI4sp5r8r5qYoKeEx537Gnlkq1dpTrYY&e=