<div dir="ltr"><div>Thanks for pointing that out, I have rectified the indentation errors.<br><br></div>Here's the patch for atsam:<br>From 8e5e17525a76e68bc4d869d0af9700aaa5628483 Mon Sep 17 00:00:00 2001<br>From: Udit agarwal <<a href="mailto:dev.madaari@gmail.com">dev.madaari@gmail.com</a>><br>Date: Fri, 16 Mar 2018 14:54:53 +0530<br>Subject: [PATCH] arm/atsam: protect TRNG_GetRandData with mutex<br><br>---<br> c/src/lib/libbsp/arm/atsam/startup/getentropy-trng.c | 7 ++++++-<br> 1 file changed, 6 insertions(+), 1 deletion(-)<br><br>diff --git a/c/src/lib/libbsp/arm/atsam/startup/getentropy-trng.c b/c/src/lib/libbsp/arm/atsam/startup/getentropy-trng.c<br>index 11e24dc..54a1cef 100644<br>--- a/c/src/lib/libbsp/arm/atsam/startup/getentropy-trng.c<br>+++ b/c/src/lib/libbsp/arm/atsam/startup/getentropy-trng.c<br>@@ -17,6 +17,9 @@<br> #include <string.h><br> #include <rtems/sysinit.h><br> <br>+static rtems_mutex atsam_trng_mutex =<br>+ RTEMS_MUTEX_INITIALIZER("atsam_trng");<br>+<br> static void atsam_trng_enable(void)<br> {<br> PMC_EnablePeripheral(ID_TRNG);<br>@@ -25,6 +28,8 @@ static void atsam_trng_enable(void)<br> <br> int getentropy(void *ptr, size_t n)<br> {<br>+ rtems_mutex_lock(&atsam_trng_mutex);<br>+<br> while (n > 0) {<br> uint32_t random;<br> size_t copy;<br>@@ -50,7 +55,7 @@ int getentropy(void *ptr, size_t n)<br> n -= copy;<br> ptr += copy;<br> }<br>-<br>+ rtems_mutex_unlock(&atsam_trng_mutex);<br> return 0;<br> }<br> <br>-- <br>1.9.1<br></div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Mar 15, 2018 at 7:52 PM, Gedare Bloom <span dir="ltr"><<a href="mailto:gedare@rtems.org" target="_blank">gedare@rtems.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">On Thu, Mar 15, 2018 at 7:00 AM, Udit agarwal <<a href="mailto:dev.madaari@gmail.com">dev.madaari@gmail.com</a>> wrote:<br>
><br>
><br>
> On Thu, Mar 15, 2018 at 2:38 PM, Sebastian Huber<br>
> <<a href="mailto:sebastian.huber@embedded-brains.de">sebastian.huber@embedded-<wbr>brains.de</a>> wrote:<br>
>><br>
>> On 15/03/18 09:20, Udit agarwal wrote:<br>
>>><br>
>>> Also, will it be ok to keep atsam_trng_mutex even after user has finished<br>
>>> using getentropy() i.e when we don't use destroy(&atsam_trng_mutex) at all?<br>
>><br>
>><br>
>> Why do you want to destroy the mutex?<br>
><br>
> Just trying to reduce redundancy, but then i don't think that's a good idea.<br>
> BTW, here's atsam patch, please have a look:<br>
><br>
> From 35313002ea19715c5914c5983a2447<wbr>1b0763aa68 Mon Sep 17 00:00:00 2001<br>
> From: Udit agarwal <<a href="mailto:dev.madaari@gmail.com">dev.madaari@gmail.com</a>><br>
> Date: Thu, 15 Mar 2018 16:21:51 +0530<br>
> Subject: [PATCH] Added mutex across TRNG_GetRandData<br>
<br>
</span>In the commit message, identify the rtems subsystem. I guess we don't<br>
have detailed advice on the wiki for this, but here I guess we usually<br>
would have something like "arm/atsam: protect TRNG_GetRandData with<br>
mutex"<br>
<span class=""><br>
><br>
> ---<br>
> c/src/lib/libbsp/arm/atsam/<wbr>startup/getentropy-trng.c | 7 +++++++<br>
> 1 file changed, 7 insertions(+)<br>
><br>
> diff --git a/c/src/lib/libbsp/arm/atsam/<wbr>startup/getentropy-trng.c<br>
> b/c/src/lib/libbsp/arm/atsam/<wbr>startup/getentropy-trng.c<br>
> index 11e24dc..2789970 100644<br>
> --- a/c/src/lib/libbsp/arm/atsam/<wbr>startup/getentropy-trng.c<br>
> +++ b/c/src/lib/libbsp/arm/atsam/<wbr>startup/getentropy-trng.c<br>
> @@ -16,6 +16,9 @@<br>
> #include <unistd.h><br>
> #include <string.h><br>
> #include <rtems/sysinit.h><br>
> +#include <rtems/thread.h><br>
> +<br>
> +static rtems_mutex atsam_trng_mutex =<br>
> RTEMS_MUTEX_INITIALIZER("<wbr>atsam_trng");<br>
><br>
</span>The second line should be indented 2 more levels (4 spaces).<br>
<a href="https://devel.rtems.org/wiki/Developer/Coding/80_characters_per_line" rel="noreferrer" target="_blank">https://devel.rtems.org/wiki/<wbr>Developer/Coding/80_<wbr>characters_per_line</a><br>
<span class=""><br>
> static void atsam_trng_enable(void)<br>
> {<br>
> @@ -25,6 +28,9 @@ static void atsam_trng_enable(void)<br>
><br>
> int getentropy(void *ptr, size_t n)<br>
> {<br>
> +<br>
> + rtems_mutex_lock(&atsam_trng_<wbr>mutex);<br>
</span>The number of indent spaces here look wrong to me. It should be 2.<br>
<span class=""><br>
> +<br>
> while (n > 0) {<br>
> uint32_t random;<br>
> size_t copy;<br>
> @@ -51,6 +57,7 @@ int getentropy(void *ptr, size_t n)<br>
> ptr += copy;<br>
> }<br>
><br>
> + rtems_mutex_unlock(&atsam_<wbr>trng_mutex);<br>
</span>ditto.<br>
<span class="im HOEnZb"><br>
> return 0;<br>
> }<br>
><br>
> --<br>
> 1.9.1<br>
><br>
><br>
>><br>
>><br>
>><br>
>> --<br>
>> Sebastian Huber, embedded brains GmbH<br>
>><br>
>> Address : Dornierstr. 4, D-82178 Puchheim, Germany<br>
>> Phone : +49 89 189 47 41-16<br>
>> Fax : +49 89 189 47 41-09<br>
>> E-Mail : <a href="mailto:sebastian.huber@embedded-brains.de">sebastian.huber@embedded-<wbr>brains.de</a><br>
>> PGP : Public key available on request.<br>
>><br>
>> Diese Nachricht ist keine geschäftliche Mitteilung im Sinne des EHUG.<br>
>><br>
><br>
><br>
</span><div class="HOEnZb"><div class="h5">> ______________________________<wbr>_________________<br>
> devel mailing list<br>
> <a href="mailto:devel@rtems.org">devel@rtems.org</a><br>
> <a href="http://lists.rtems.org/mailman/listinfo/devel" rel="noreferrer" target="_blank">http://lists.rtems.org/<wbr>mailman/listinfo/devel</a><br>
</div></div></blockquote></div><br></div>