freemyipod r387 - Code Review

Jump to: navigation, search
Repository:freemyipod
Revision:r386‎ | r387 | r388 >
Date:21:03, 26 December 2010
Author:theseven
Status:new
Tags:
Comment:
emBIOS: Be a bit more paranoid about race conditions
Modified paths:
  • /embios/trunk/target/ipodnano2g/clockgates.c (modified) (history)
  • /embios/trunk/target/ipodnano2g/hmacsha1.c (modified) (history)
  • /embios/trunk/target/ipodnano2g/hwkeyaes.c (modified) (history)
  • /embios/trunk/target/ipodnano2g/interrupt.c (modified) (history)
  • /embios/trunk/target/ipodnano3g/clockgates.c (modified) (history)
  • /embios/trunk/target/ipodnano3g/hwkeyaes.c (modified) (history)

Diff [purge]

Index: embios/trunk/target/ipodnano2g/clockgates.c
@@ -27,6 +27,8 @@
2828
2929 void clockgate_enable(int gate, bool enable)
3030 {
 31+ uint32_t mode = enter_critical_section();
3132 if (enable) PWRCON(gate >> 5) &= ~(1 << (gate & 0x1f));
3233 else PWRCON(gate >> 5) |= 1 << (gate & 0x1f);
 34+ leave_critical_section(mode);
3335 }
Index: embios/trunk/target/ipodnano2g/hwkeyaes.c
@@ -27,10 +27,14 @@
2828 #include "thread.h"
2929
3030
 31+struct mutex hwkeyaes_mutex;
 32+
 33+
3134 void hwkeyaes(enum hwkeyaes_direction direction, uint32_t keyidx, void* data, uint32_t size)
3235 {
3336 uint32_t ptr, i;
3437 uint32_t go = 1;
 38+ mutex_lock(&hwkeyaes_mutex, TIMEOUT_BLOCK);
3539 PWRCON(1) &= ~0x400;
3640 AESTYPE = keyidx;
3741 AESUNKREG0 = 1;
@@ -70,4 +74,5 @@
7175 }
7276 AESCONTROL = 0;
7377 PWRCON(1) |= 0x400;
 78+ mutex_unlock(&hwkeyaes_mutex);
7479 }
Index: embios/trunk/target/ipodnano2g/hmacsha1.c
@@ -27,10 +27,14 @@
2828 #include "thread.h"
2929
3030
 31+struct mutex hmacsha1_mutex;
 32+
 33+
3134 void hmacsha1(void* data, uint32_t size, void* result)
3235 {
3336 uint32_t ptr, i;
3437 uint32_t ctrl = 2;
 38+ mutex_lock(&hmacsha1_mutex, TIMEOUT_BLOCK);
3539 PWRCON(1) &= ~4;
3640 for (ptr = 0; ptr < (size >> 2); ptr += 0x10)
3741 {
@@ -41,4 +45,5 @@
4246 }
4347 for (i = 0; i < 5; i ++) ((uint32_t*)result)[i] = HASHRESULT[i];
4448 PWRCON(1) |= 4;
 49+ mutex_unlock(&hmacsha1_mutex);
4550 }
Index: embios/trunk/target/ipodnano2g/interrupt.c
@@ -132,8 +132,10 @@
133133
134134 void interrupt_enable(int irq, bool state)
135135 {
 136+ uint32_t mode = enter_critical_section();
136137 if (state) INTMSK |= 1 << irq;
137138 else INTMSK &= ~(1 << irq);
 139+ leave_critical_section(mode);
138140 }
139141
140142 void interrupt_set_handler(int irq, void* handler)
Index: embios/trunk/target/ipodnano3g/clockgates.c
@@ -27,6 +27,8 @@
2828
2929 void clockgate_enable(int gate, bool enable)
3030 {
 31+ uint32_t mode = enter_critical_section();
3132 if (enable) PWRCON(gate >> 5) &= ~(1 << (gate & 0x1f));
3233 else PWRCON(gate >> 5) |= 1 << (gate & 0x1f);
 34+ leave_critical_section(mode);
3335 }
Index: embios/trunk/target/ipodnano3g/hwkeyaes.c
@@ -27,9 +27,13 @@
2828 #include "thread.h"
2929
3030
 31+struct mutex hwkeyaes_mutex;
 32+
 33+
3134 void hwkeyaes(enum hwkeyaes_direction direction, uint32_t keyidx, void* data, uint32_t size)
3235 {
3336 int i;
 37+ mutex_lock(&hwkeyaes_mutex, TIMEOUT_BLOCK);
3438 clockgate_enable(10, true);
3539 for (i = 0; i < 4; i++) AESIV[i] = 0;
3640 AESUNKREG0 = 1;
@@ -52,4 +56,5 @@
5357 invalidate_dcache();
5458 while (!(AESSTATUS & 0xf)) sleep(100);
5559 clockgate_enable(10, false);
 60+ mutex_unlock(&hwkeyaes_mutex);
5661 }