From 4a4c8218eed10132c7e37a603575ee7d2a7e6a9f Mon Sep 17 00:00:00 2001 From: cinap_lenrek Date: Wed, 26 Dec 2012 17:53:12 +0100 Subject: [PATCH] devsd: fix possible sdbio() race with inquiry data changing (due to ahci hotplug) the unit inquiry data might change in case the drive got pulled with ahci. so keep track if we locked the ctl in a local stack variable instead of relying on that the inquiry data stays the same. --- sys/src/9/port/devsd.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/sys/src/9/port/devsd.c b/sys/src/9/port/devsd.c index b4cbd71f5..0d2a32319 100644 --- a/sys/src/9/port/devsd.c +++ b/sys/src/9/port/devsd.c @@ -770,7 +770,7 @@ sdclose(Chan* c) static long sdbio(Chan* c, int write, char* a, long len, uvlong off) { - int nchange, hard, allocd; + int nchange, hard, allocd, locked; long l; uchar *b; SDpart *pp; @@ -832,7 +832,8 @@ sdbio(Chan* c, int write, char* a, long len, uvlong off) poperror(); return 0; } - if(!(unit->inquiry[1] & 0x80)){ + locked = (unit->inquiry[1] & 0x80) != 0; + if(!locked){ qunlock(&unit->ctl); poperror(); } @@ -854,7 +855,7 @@ sdbio(Chan* c, int write, char* a, long len, uvlong off) if(waserror()){ if(allocd) sdfree(b); - if(!(unit->inquiry[1] & 0x80)) + if(!locked) decref(&sdev->r); /* gadverdamme! */ nexterror(); } @@ -896,7 +897,7 @@ sdbio(Chan* c, int write, char* a, long len, uvlong off) sdfree(b); poperror(); - if(unit->inquiry[1] & 0x80){ + if(locked){ qunlock(&unit->ctl); poperror(); }