floppy.c IRQ/DMA potential bug?

Taral (taral@cyberjunkie.com)
Thu, 4 Mar 1999 14:45:05 -0600


--Boundary-=_nWlrBbmQBhCDarzOwKkYHIDdqSCD
Content-Type: text/plain
Content-Transfer-Encoding: quoted-printable

Looking at ftape, there's a patch to floppy.c for versions up through 2.1=
=2Ex,
and the patch still applies to 2.2.2... It fixes a potential problem wher=
e the
IRQ is allocated before the DMA, and if an IRQ from the FDC arrives betwe=
en
those two, the IRQ handler will try to access the (nonexistent) DMA buffe=
r.

Attached the the patch as it would apply to 2.2.2 -- not sure if it's sti=
ll
needed.

Taral
--Boundary-=_nWlrBbmQBhCDarzOwKkYHIDdqSCD
Content-Type: text/plain;
name="floppy.c.diff"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment; filename="floppy.c.diff"

--- linux/drivers/block/floppy.c.old=09Sun Jan 10 11:59:59 1999
+++ linux/drivers/block/floppy.c=09Thu Mar 4 14:43:26 1999
@@ -4240,20 +4240,10 @@ static int floppy_grab_irq_and_dma(void)
=09}
=09INT_ON;
=09MOD_INC_USE_COUNT;
-=09if (fd_request_irq()) {
-=09=09DPRINT("Unable to grab IRQ%d for the floppy driver\n",
-=09=09=09FLOPPY_IRQ);
-=09=09MOD_DEC_USE_COUNT;
-=09=09usage_count--;
-=09=09return -1;
-=09}
=09if (fd_request_dma()) {
=09=09DPRINT("Unable to grab DMA%d for the floppy driver\n",
=09=09=09FLOPPY_DMA);
-=09=09fd_free_irq();
-=09=09MOD_DEC_USE_COUNT;
-=09=09usage_count--;
-=09=09return -1;
+=09=09goto out_no_dma;
=09}
=20
=09for (fdc=3D0; fdc< N_FDC; fdc++){
@@ -4261,15 +4251,7 @@ static int floppy_grab_irq_and_dma(void)
=09=09=09if (check_region(FDCS->address, 6) < 0 ||
=09=09=09 check_region(FDCS->address+7, 1) < 0) {
=09=09=09=09DPRINT("Floppy io-port 0x%04lx in use\n", FDCS->address);
-=09=09=09=09fd_free_irq();
-=09=09=09=09fd_free_dma();
-=09=09=09=09while(--fdc >=3D 0) {
-=09=09=09=09=09release_region(FDCS->address, 6);
-=09=09=09=09=09release_region(FDCS->address+7, 1);
-=09=09=09=09}
-=09=09=09=09MOD_DEC_USE_COUNT;
-=09=09=09=09usage_count--;
-=09=09=09=09return -1;
+=09=09=09=09goto release_resources;
=09=09=09}
=09=09=09request_region(FDCS->address, 6, "floppy");
=09=09=09request_region(FDCS->address+7, 1, "floppy DIR");
@@ -4277,6 +4259,11 @@ static int floppy_grab_irq_and_dma(void)
=09=09=09 * Unfortunately, Adaptec doesn't know this :-(, */
=09=09}
=09}
+=09if (fd_request_irq()) {
+=09=09DPRINT("Unable to grab IRQ%d for the floppy driver\n",
+=09=09=09FLOPPY_IRQ);
+=09=09goto release_resources;
+=09}
=09for (fdc=3D0; fdc< N_FDC; fdc++){
=09=09if (FDCS->address !=3D -1){
=09=09=09reset_fdc_info(1);
@@ -4296,6 +4283,19 @@ static int floppy_grab_irq_and_dma(void)
=09fdc =3D 0;
=09irqdma_allocated =3D 1;
=09return 0;
+
+release_resources:
+=09fd_free_dma();
+=09while(--fdc >=3D 0)=20
+=09=09if (FDCS->address !=3D -1) {
+=09=09=09release_region(FDCS->address, 6);
+=09=09=09release_region(FDCS->address+7, 1);
+=09=09}
+=09}
+out_no_dma:
+=09MOD_DEC_USE_COUNT;
+=09usage_count--;
+=09return -1;
}
=20
static void floppy_release_irq_and_dma(void)

--Boundary-=_nWlrBbmQBhCDarzOwKkYHIDdqSCD--

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/