floppy: fix div-by-zero in setup_format_params
[linux-2.6-microblaze.git] / drivers / block / floppy.c
index 9fb9b31..51246bc 100644 (file)
@@ -2120,6 +2120,9 @@ static void setup_format_params(int track)
        raw_cmd->kernel_data = floppy_track_buffer;
        raw_cmd->length = 4 * F_SECT_PER_TRACK;
 
+       if (!F_SECT_PER_TRACK)
+               return;
+
        /* allow for about 30ms for data transport per track */
        head_shift = (F_SECT_PER_TRACK + 5) / 6;
 
@@ -3232,6 +3235,8 @@ static int set_geometry(unsigned int cmd, struct floppy_struct *g,
        /* sanity checking for parameters. */
        if (g->sect <= 0 ||
            g->head <= 0 ||
+           /* check for zero in F_SECT_PER_TRACK */
+           (unsigned char)((g->sect << 2) >> FD_SIZECODE(g)) == 0 ||
            g->track <= 0 || g->track > UDP->tracks >> STRETCH(g) ||
            /* check if reserved bits are set */
            (g->stretch & ~(FD_STRETCH | FD_SWAPSIDES | FD_SECTBASEMASK)) != 0)