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