[PATCH 10/32] leon, grcan: protect statistics on copy to user

Daniel Hellstrom daniel at gaisler.com
Thu May 11 14:25:55 UTC 2017


From: Martin Aberg <maberg at gaisler.com>

Locking the stats structure when copying to user buffer ensures a consistent
view to the user.
---
 c/src/lib/libbsp/sparc/shared/can/grcan.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/c/src/lib/libbsp/sparc/shared/can/grcan.c b/c/src/lib/libbsp/sparc/shared/can/grcan.c
index 409e68b..003cecf 100644
--- a/c/src/lib/libbsp/sparc/shared/can/grcan.c
+++ b/c/src/lib/libbsp/sparc/shared/can/grcan.c
@@ -1612,13 +1612,16 @@ int grcan_set_rxcomplete(void *d, int complete)
 int grcan_get_stats(void *d, struct grcan_stats *stats)
 {
 	struct grcan_priv *pDev = d;
+	SPIN_IRQFLAGS(oldLevel);
 
 	FUNCDBG();
 
 	if ( !stats )
 		return -1;
 
+	SPIN_LOCK_IRQ(&pDev->devlock, oldLevel);
 	*stats = pDev->stats;
+	SPIN_UNLOCK_IRQ(&pDev->devlock, oldLevel);
 
 	return 0;
 }
-- 
2.7.4




More information about the devel mailing list