ref: 4a4c8218eed10132c7e37a603575ee7d2a7e6a9f
parent: 7ceff03db37d98e1dc634198fcee4206d8318499
author: cinap_lenrek <cinap_lenrek@gmx.de>
date: Wed Dec 26 12:53:12 EST 2012
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.
--- a/sys/src/9/port/devsd.c
+++ b/sys/src/9/port/devsd.c
@@ -770,7 +770,7 @@
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 @@
poperror();
return 0;
}
- if(!(unit->inquiry[1] & 0x80)){+ locked = (unit->inquiry[1] & 0x80) != 0;
+ if(!locked){qunlock(&unit->ctl);
poperror();
}
@@ -854,7 +855,7 @@
if(waserror()){if(allocd)
sdfree(b);
- if(!(unit->inquiry[1] & 0x80))
+ if(!locked)
decref(&sdev->r); /* gadverdamme! */
nexterror();
}
@@ -896,7 +897,7 @@
sdfree(b);
poperror();
- if(unit->inquiry[1] & 0x80){+ if(locked){qunlock(&unit->ctl);
poperror();
}
--
⑨