From 24c28f2576c965815722f35795655a5199016a4e Mon Sep 17 00:00:00 2001 From: bz Date: Sun, 20 Apr 2008 17:45:32 +0000 Subject: [PATCH] devclass_get_maxunit() returns n+1 with n starting at 0. So if we have channel 0..3 devclass_get_maxunit is 4. It's never been a problem as devclass_get_device() has catched a possibly bad input. Discussed with: scottl --- sys/dev/ata/ata-all.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/sys/dev/ata/ata-all.c b/sys/dev/ata/ata-all.c index 597bb3818b57..83da7ff8bfd9 100644 --- a/sys/dev/ata/ata-all.c +++ b/sys/dev/ata/ata-all.c @@ -366,12 +366,13 @@ ata_ioctl(struct cdev *dev, u_long cmd, caddr_t data, switch (cmd) { case IOCATAGMAXCHANNEL: + /* In case we have channel 0..n this will return n+1. */ *value = devclass_get_maxunit(ata_devclass); error = 0; break; case IOCATAREINIT: - if (*value > devclass_get_maxunit(ata_devclass) || + if (*value >= devclass_get_maxunit(ata_devclass) || !(device = devclass_get_device(ata_devclass, *value))) return ENXIO; error = ata_reinit(device); @@ -379,7 +380,7 @@ ata_ioctl(struct cdev *dev, u_long cmd, caddr_t data, break; case IOCATAATTACH: - if (*value > devclass_get_maxunit(ata_devclass) || + if (*value >= devclass_get_maxunit(ata_devclass) || !(device = devclass_get_device(ata_devclass, *value))) return ENXIO; /* XXX SOS should enable channel HW on controller */ @@ -387,7 +388,7 @@ ata_ioctl(struct cdev *dev, u_long cmd, caddr_t data, break; case IOCATADETACH: - if (*value > devclass_get_maxunit(ata_devclass) || + if (*value >= devclass_get_maxunit(ata_devclass) || !(device = devclass_get_device(ata_devclass, *value))) return ENXIO; error = ata_detach(device); @@ -395,7 +396,7 @@ ata_ioctl(struct cdev *dev, u_long cmd, caddr_t data, break; case IOCATADEVICES: - if (devices->channel > devclass_get_maxunit(ata_devclass) || + if (devices->channel >= devclass_get_maxunit(ata_devclass) || !(device = devclass_get_device(ata_devclass, devices->channel))) return ENXIO; bzero(devices->name[0], 32);