Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1623507
| From | PrasannaKumar Muralidharan <prasannatsmkumar@gmail.com> |
|---|---|
| Newsgroups | linux.kernel |
| Subject | Re: [PATCH 2/2] hwrng: mtk: Add driver for hardware random generator on MT7623 SoC |
| Date | 2017-04-14 07:00 +0200 |
| Message-ID | <tw1uV-55U-3@gated-at.bofh.it> (permalink) |
| References | <tvH3c-7S2-13@gated-at.bofh.it> <tvH3c-7S2-15@gated-at.bofh.it> <tvIsh-kh-7@gated-at.bofh.it> <tw0yR-4r2-5@gated-at.bofh.it> |
| Organization | linux.* mail to news gateway |
On 14 April 2017 at 09:28, Sean Wang <sean.wang@mediatek.com> wrote:
>
> Hi PrasannaKumar,
>
> Add my comments inline
>
>>
>> Use readl_poll_timeout_atomic's return value or -EIO instead of
>> !!ready. This will simplify mtk_rng_read.
>>
>
> !!ready provided is in order to let blocking/non-blocking case could
> share same code path. And readl_poll_timeout_atomic only handles
> blocking case.
Missed this point. Makes sense. My previous comment about return value
in mtk_rng_read is invalid as I based it on a wrong assumption.
>
>> > +static int mtk_rng_read(struct hwrng *rng, void *buf, size_t max, bool wait)
>> > +{
>> > + struct mtk_rng *priv = to_mtk_rng(rng);
>> > + int retval = 0;
>> > +
>> > + while (max >= sizeof(u32)) {
>> > + if (!mtk_rng_wait_ready(rng, wait))
>> > + break;
>> > +
>> > + *(u32 *)buf = readl(priv->base + RNG_DATA);
>> > + retval += sizeof(u32);
>> > + buf += sizeof(u32);
>> > + max -= sizeof(u32);
>> > + }
>> > +
>> > + if (unlikely(wait && max))
>> > + dev_warn(priv->dev, "timeout might be not properly set\n");
>>
>> Is this really necessary? Better to choose proper timeout than
>> providing this warning message. In rare cases if the timeout could
>> occur due to some reason (may be a hardware fault) print appropriate
>> warning message.
>
> It is good, I will choose the proper timeout and remove the log in the
> next one.
>
>>
>> > + return retval || !wait ? retval : -EIO;
>> > +}
>>
>> Set retavl to mtk_rng_wait_ready and return retval.
>>
>
> Maybe i didn't get your points exactly. Adding some explanation about
> thoughts here.
>
> "return retval || !wait ? retval : -EIO;" I use can also help handling
> the both cases in one line which i think is elegant enough.
>
> And retval is accumulated with each round if some data's existing in
> hardware, so we don't return the value from mtk_rng_wait_ready().
retval can be 0 only when mkt_rng_wait_ready fails, returning 0 when
wait is true is confusing. Expected return value when 0 bytes is read
from device and wait is true is not clearly documented.
"return retval || !wait ? retval : -EIO;" is also fine.
Overall the code looks good to me. You can add:
Reviewed-by: PrasannaKumar Muralidharan <prasannatsmkumar@gmail.com>.
Regards,
PrasannaKumar
Back to linux.kernel | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
[PATCH 0/2] hwrng: mtk: add support for hardware random generator on MT7623 SoC <sean.wang@mediatek.com> - 2017-04-13 09:10 +0200
[PATCH 2/2] hwrng: mtk: Add driver for hardware random generator on MT7623 SoC <sean.wang@mediatek.com> - 2017-04-13 09:10 +0200
Re: [PATCH 2/2] hwrng: mtk: Add driver for hardware random generator on MT7623 SoC PrasannaKumar Muralidharan <prasannatsmkumar@gmail.com> - 2017-04-13 10:40 +0200
Re: [PATCH 2/2] hwrng: mtk: Add driver for hardware random generator on MT7623 SoC Sean Wang <sean.wang@mediatek.com> - 2017-04-14 06:00 +0200
Re: [PATCH 2/2] hwrng: mtk: Add driver for hardware random generator on MT7623 SoC PrasannaKumar Muralidharan <prasannatsmkumar@gmail.com> - 2017-04-14 07:00 +0200
Re: [PATCH 2/2] hwrng: mtk: Add driver for hardware random generator on MT7623 SoC Corentin Labbe <clabbe.montjoie@gmail.com> - 2017-04-13 13:10 +0200
Re: [PATCH 2/2] hwrng: mtk: Add driver for hardware random generator on MT7623 SoC Sean Wang <sean.wang@mediatek.com> - 2017-04-14 05:40 +0200
[PATCH 1/2] dt-bindings: hwrng: Add Mediatek hardware random generator bindings <sean.wang@mediatek.com> - 2017-04-13 09:10 +0200
Re: [PATCH 1/2] dt-bindings: hwrng: Add Mediatek hardware random generator bindings Rob Herring <robh@kernel.org> - 2017-04-19 23:30 +0200
csiph-web