Commit 05f5e319 authored by Willy Tarreau's avatar Willy Tarreau Committed by Denis Efremov

floppy: cleanup: do not iterate on current_fdc in do_floppy_init()

There's no need to iterate on current_fdc in do_floppy_init() anymore,
in the first case it's only used as an array index to access fdc_state[],
so let's get rid of this confusing assignment. The second case is a bit
trickier because user_reset_fdc() needs to already know current_fdc when
called with drive==-1 due to this call chain:

    user_reset_fdc()
      lock_fdc()
        set_fdc()
           drive<0 ==> new_fdc = current_fdc

Note that current_drive is not used in this code part and may even not
match a unit belonging to current_fdc. Instead of passing -1 we can
simply pass the first drive of the FDC being initialized, which is even
cleaner as it will allow the function chain above to consistently assign
both variables.

Link: https://lore.kernel.org/r/20200410093023.14499-1-w@1wt.euSigned-off-by: default avatarWilly Tarreau <w@1wt.eu>
Signed-off-by: default avatarDenis Efremov <efremov@linux.com>
parent 12aebfac
...@@ -4657,16 +4657,15 @@ static int __init do_floppy_init(void) ...@@ -4657,16 +4657,15 @@ static int __init do_floppy_init(void)
config_types(); config_types();
for (i = 0; i < N_FDC; i++) { for (i = 0; i < N_FDC; i++) {
current_fdc = i; memset(&fdc_state[i], 0, sizeof(*fdc_state));
memset(&fdc_state[current_fdc], 0, sizeof(*fdc_state)); fdc_state[i].dtr = -1;
fdc_state[current_fdc].dtr = -1; fdc_state[i].dor = 0x4;
fdc_state[current_fdc].dor = 0x4;
#if defined(__sparc__) || defined(__mc68000__) #if defined(__sparc__) || defined(__mc68000__)
/*sparcs/sun3x don't have a DOR reset which we can fall back on to */ /*sparcs/sun3x don't have a DOR reset which we can fall back on to */
#ifdef __mc68000__ #ifdef __mc68000__
if (MACH_IS_SUN3X) if (MACH_IS_SUN3X)
#endif #endif
fdc_state[current_fdc].version = FDC_82072A; fdc_state[i].version = FDC_82072A;
#endif #endif
} }
...@@ -4708,30 +4707,29 @@ static int __init do_floppy_init(void) ...@@ -4708,30 +4707,29 @@ static int __init do_floppy_init(void)
msleep(10); msleep(10);
for (i = 0; i < N_FDC; i++) { for (i = 0; i < N_FDC; i++) {
current_fdc = i; fdc_state[i].driver_version = FD_DRIVER_VERSION;
fdc_state[current_fdc].driver_version = FD_DRIVER_VERSION;
for (unit = 0; unit < 4; unit++) for (unit = 0; unit < 4; unit++)
fdc_state[current_fdc].track[unit] = 0; fdc_state[i].track[unit] = 0;
if (fdc_state[current_fdc].address == -1) if (fdc_state[i].address == -1)
continue; continue;
fdc_state[current_fdc].rawcmd = 2; fdc_state[i].rawcmd = 2;
if (user_reset_fdc(-1, FD_RESET_ALWAYS, false)) { if (user_reset_fdc(REVDRIVE(i, 0), FD_RESET_ALWAYS, false)) {
/* free ioports reserved by floppy_grab_irq_and_dma() */ /* free ioports reserved by floppy_grab_irq_and_dma() */
floppy_release_regions(current_fdc); floppy_release_regions(i);
fdc_state[current_fdc].address = -1; fdc_state[i].address = -1;
fdc_state[current_fdc].version = FDC_NONE; fdc_state[i].version = FDC_NONE;
continue; continue;
} }
/* Try to determine the floppy controller type */ /* Try to determine the floppy controller type */
fdc_state[current_fdc].version = get_fdc_version(current_fdc); fdc_state[i].version = get_fdc_version(i);
if (fdc_state[current_fdc].version == FDC_NONE) { if (fdc_state[i].version == FDC_NONE) {
/* free ioports reserved by floppy_grab_irq_and_dma() */ /* free ioports reserved by floppy_grab_irq_and_dma() */
floppy_release_regions(current_fdc); floppy_release_regions(i);
fdc_state[current_fdc].address = -1; fdc_state[i].address = -1;
continue; continue;
} }
if (can_use_virtual_dma == 2 && if (can_use_virtual_dma == 2 &&
fdc_state[current_fdc].version < FDC_82072A) fdc_state[i].version < FDC_82072A)
can_use_virtual_dma = 0; can_use_virtual_dma = 0;
have_no_fdc = 0; have_no_fdc = 0;
...@@ -4739,7 +4737,7 @@ static int __init do_floppy_init(void) ...@@ -4739,7 +4737,7 @@ static int __init do_floppy_init(void)
* properly, so force a reset for the standard FDC clones, * properly, so force a reset for the standard FDC clones,
* to avoid interrupt garbage. * to avoid interrupt garbage.
*/ */
user_reset_fdc(-1, FD_RESET_ALWAYS, false); user_reset_fdc(REVDRIVE(i, 0), FD_RESET_ALWAYS, false);
} }
current_fdc = 0; current_fdc = 0;
cancel_delayed_work(&fd_timeout); cancel_delayed_work(&fd_timeout);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment