From: Alan Cox Date: Sat, 22 Apr 2017 08:26:21 +0000 (+0100) Subject: devices: Fix an off by one error in the maximum device checks X-Git-Url: https://git.ndcode.org/public/gitweb.cgi?a=commitdiff_plain;h=63d54204440e297b242a4b7b8c3fd7eedc467f34;p=FUZIX.git devices: Fix an off by one error in the maximum device checks If we have 1 major then the highest permitted device is 0,255 not 1, 255. This only ever showed up if you either mknod a device once bigger than that supported or attempt to boot a device one higher than the limit. --- diff --git a/Kernel/platform-68hc11test/devices.c b/Kernel/platform-68hc11test/devices.c index df1dcdd8..6c15d6e0 100644 --- a/Kernel/platform-68hc11test/devices.c +++ b/Kernel/platform-68hc11test/devices.c @@ -27,7 +27,7 @@ bool validdev(uint16_t dev) { /* This is a bit uglier than needed but the right hand side is a constant this way */ - if(dev > ((sizeof(dev_tab)/sizeof(struct devsw)) << 8) + 255) + if(dev > ((sizeof(dev_tab)/sizeof(struct devsw)) << 8) - 1) return false; else return true; diff --git a/Kernel/platform-atarist/devices.c b/Kernel/platform-atarist/devices.c index fe99fe2c..50f0f27f 100644 --- a/Kernel/platform-atarist/devices.c +++ b/Kernel/platform-atarist/devices.c @@ -28,7 +28,7 @@ bool validdev(uint16_t dev) { /* This is a bit uglier than needed but the right hand side is a constant this way */ - if(dev > ((sizeof(dev_tab)/sizeof(struct devsw)) << 8) + 255) + if(dev > ((sizeof(dev_tab)/sizeof(struct devsw)) << 8) - 1) return false; else return true; diff --git a/Kernel/platform-coco2/devices.c b/Kernel/platform-coco2/devices.c index 5c3689bd..f62ec4a4 100644 --- a/Kernel/platform-coco2/devices.c +++ b/Kernel/platform-coco2/devices.c @@ -37,7 +37,7 @@ bool validdev(uint16_t dev) { /* This is a bit uglier than needed but the right hand side is a constant this way */ - if(dev > ((sizeof(dev_tab)/sizeof(struct devsw)) << 8) + 255) + if(dev > ((sizeof(dev_tab)/sizeof(struct devsw)) << 8) - 1) return false; else return true; diff --git a/Kernel/platform-coco2cart/devices.c b/Kernel/platform-coco2cart/devices.c index 3bcb457d..d0c5488b 100644 --- a/Kernel/platform-coco2cart/devices.c +++ b/Kernel/platform-coco2cart/devices.c @@ -39,7 +39,7 @@ bool validdev(uint16_t dev) { /* This is a bit uglier than needed but the right hand side is a constant this way */ - if(dev > ((sizeof(dev_tab)/sizeof(struct devsw)) << 8) + 255) + if(dev > ((sizeof(dev_tab)/sizeof(struct devsw)) << 8) - 1) return false; else return true; diff --git a/Kernel/platform-coco3/devices.c b/Kernel/platform-coco3/devices.c index 79445ca7..27c6c4ac 100644 --- a/Kernel/platform-coco3/devices.c +++ b/Kernel/platform-coco3/devices.c @@ -38,7 +38,7 @@ bool validdev(uint16_t dev) { /* This is a bit uglier than needed but the right hand side is a constant this way */ - if(dev > ((sizeof(dev_tab)/sizeof(struct devsw)) << 8) + 255) + if(dev > ((sizeof(dev_tab)/sizeof(struct devsw)) << 8) - 1) return false; else return true; diff --git a/Kernel/platform-dragon-nx32/devices.c b/Kernel/platform-dragon-nx32/devices.c index 4b37f757..afa4c6c4 100644 --- a/Kernel/platform-dragon-nx32/devices.c +++ b/Kernel/platform-dragon-nx32/devices.c @@ -42,7 +42,7 @@ bool validdev(uint16_t dev) { /* This is a bit uglier than needed but the right hand side is a constant this way */ - if(dev > ((sizeof(dev_tab)/sizeof(struct devsw)) << 8) + 255) + if(dev > ((sizeof(dev_tab)/sizeof(struct devsw)) << 8) - 1) return false; else return true; diff --git a/Kernel/platform-dragon/devices.c b/Kernel/platform-dragon/devices.c index a188243c..960fbcb2 100644 --- a/Kernel/platform-dragon/devices.c +++ b/Kernel/platform-dragon/devices.c @@ -34,7 +34,7 @@ bool validdev(uint16_t dev) { /* This is a bit uglier than needed but the right hand side is a constant this way */ - if(dev > ((sizeof(dev_tab)/sizeof(struct devsw)) << 8) + 255) + if(dev > ((sizeof(dev_tab)/sizeof(struct devsw)) << 8) - 1) return false; else return true; diff --git a/Kernel/platform-micropack/devices.c b/Kernel/platform-micropack/devices.c index c16f2080..2bdf907f 100644 --- a/Kernel/platform-micropack/devices.c +++ b/Kernel/platform-micropack/devices.c @@ -28,7 +28,7 @@ bool validdev(uint16_t dev) { /* This is a bit uglier than needed but the right hand side is a constant this way */ - if(dev > ((sizeof(dev_tab)/sizeof(struct devsw)) << 8) + 255) + if(dev > ((sizeof(dev_tab)/sizeof(struct devsw)) << 8) - 1) return false; else return true; diff --git a/Kernel/platform-msp430fr5969/devices.c b/Kernel/platform-msp430fr5969/devices.c index 45432833..e61ca414 100644 --- a/Kernel/platform-msp430fr5969/devices.c +++ b/Kernel/platform-msp430fr5969/devices.c @@ -33,7 +33,7 @@ bool validdev(uint16_t dev) { /* This is a bit uglier than needed but the right hand side is a constant this way */ - if(dev > ((sizeof(dev_tab)/sizeof(struct devsw)) << 8) + 255) + if(dev > ((sizeof(dev_tab)/sizeof(struct devsw)) << 8) - 1) return false; else return true; diff --git a/Kernel/platform-msx1/devices.c b/Kernel/platform-msx1/devices.c index d8e373a4..25ffd32c 100644 --- a/Kernel/platform-msx1/devices.c +++ b/Kernel/platform-msx1/devices.c @@ -29,7 +29,7 @@ bool validdev(uint16_t dev) { /* This is a bit uglier than needed but the right hand side is a constant this way */ - if(dev > ((sizeof(dev_tab)/sizeof(struct devsw)) << 8) + 255) + if(dev > ((sizeof(dev_tab)/sizeof(struct devsw)) << 8) - 1) return false; else return true; diff --git a/Kernel/platform-msx2/devices.c b/Kernel/platform-msx2/devices.c index 7a19fe62..b4658c0b 100644 --- a/Kernel/platform-msx2/devices.c +++ b/Kernel/platform-msx2/devices.c @@ -32,7 +32,7 @@ bool validdev(uint16_t dev) { /* This is a bit uglier than needed but the right hand side is a constant this way */ - if(dev > ((sizeof(dev_tab)/sizeof(struct devsw)) << 8) + 255) + if(dev > ((sizeof(dev_tab)/sizeof(struct devsw)) << 8) - 1) return false; else return true; diff --git a/Kernel/platform-mtx/devices.c b/Kernel/platform-mtx/devices.c index edddf363..937c665c 100644 --- a/Kernel/platform-mtx/devices.c +++ b/Kernel/platform-mtx/devices.c @@ -35,7 +35,7 @@ bool validdev(uint16_t dev) { /* This is a bit uglier than needed but the right hand side is a constant this way */ - if(dev > ((sizeof(dev_tab)/sizeof(struct devsw)) << 8) + 255) + if(dev > ((sizeof(dev_tab)/sizeof(struct devsw)) << 8) - 1) return false; else return true; diff --git a/Kernel/platform-multicomp09/devices.c b/Kernel/platform-multicomp09/devices.c index ad72e3d1..a3073d68 100644 --- a/Kernel/platform-multicomp09/devices.c +++ b/Kernel/platform-multicomp09/devices.c @@ -41,7 +41,7 @@ bool validdev(uint16_t dev) { /* This is a bit uglier than needed but the right hand side is a constant this way */ - if(dev > ((sizeof(dev_tab)/sizeof(struct devsw)) << 8) + 255) + if(dev > ((sizeof(dev_tab)/sizeof(struct devsw)) << 8) - 1) return false; else return true; diff --git a/Kernel/platform-n8vem-mark4/devices.c b/Kernel/platform-n8vem-mark4/devices.c index ca43ceea..0e6ad7f1 100644 --- a/Kernel/platform-n8vem-mark4/devices.c +++ b/Kernel/platform-n8vem-mark4/devices.c @@ -24,7 +24,7 @@ bool validdev(uint16_t dev) { /* This is a bit uglier than needed but the right hand side is a constant this way */ - if(dev > ((sizeof(dev_tab)/sizeof(struct devsw)) << 8) + 255) + if(dev > ((sizeof(dev_tab)/sizeof(struct devsw)) << 8) - 1) return false; else return true; diff --git a/Kernel/platform-nc100/devices.c b/Kernel/platform-nc100/devices.c index 6fb58e2b..887b350d 100644 --- a/Kernel/platform-nc100/devices.c +++ b/Kernel/platform-nc100/devices.c @@ -28,7 +28,7 @@ bool validdev(uint16_t dev) { /* This is a bit uglier than needed but the right hand side is a constant this way */ - if(dev > ((sizeof(dev_tab)/sizeof(struct devsw)) << 8) + 255) + if(dev > ((sizeof(dev_tab)/sizeof(struct devsw)) << 8) - 1) return false; else return true; diff --git a/Kernel/platform-p112/devices.c b/Kernel/platform-p112/devices.c index a4d22509..c70ee3fd 100644 --- a/Kernel/platform-p112/devices.c +++ b/Kernel/platform-p112/devices.c @@ -30,7 +30,7 @@ bool validdev(uint16_t dev) { /* This is a bit uglier than needed but the right hand side is a constant this way */ - if(dev > ((sizeof(dev_tab)/sizeof(struct devsw)) << 8) + 255) + if(dev > ((sizeof(dev_tab)/sizeof(struct devsw)) << 8) - 1) return false; else return true; diff --git a/Kernel/platform-pcw8256/devices.c b/Kernel/platform-pcw8256/devices.c index 8058595a..07dacde4 100644 --- a/Kernel/platform-pcw8256/devices.c +++ b/Kernel/platform-pcw8256/devices.c @@ -29,7 +29,7 @@ bool validdev(uint16_t dev) { /* This is a bit uglier than needed but the right hand side is a constant this way */ - if(dev > ((sizeof(dev_tab)/sizeof(struct devsw)) << 8) + 255) + if(dev > ((sizeof(dev_tab)/sizeof(struct devsw)) << 8) - 1) return false; else return true; diff --git a/Kernel/platform-pdp11/devices.c b/Kernel/platform-pdp11/devices.c index 7abcab5d..3e98824b 100644 --- a/Kernel/platform-pdp11/devices.c +++ b/Kernel/platform-pdp11/devices.c @@ -26,7 +26,7 @@ bool validdev(uint16_t dev) { /* This is a bit uglier than needed but the right hand side is a constant this way */ - if(dev > ((sizeof(dev_tab)/sizeof(struct devsw)) << 8) + 255) + if(dev > ((sizeof(dev_tab)/sizeof(struct devsw)) << 8) - 1) return false; else return true; diff --git a/Kernel/platform-plus3/devices.c b/Kernel/platform-plus3/devices.c index 51e43f36..568fe2a6 100644 --- a/Kernel/platform-plus3/devices.c +++ b/Kernel/platform-plus3/devices.c @@ -30,7 +30,7 @@ bool validdev(uint16_t dev) { /* This is a bit uglier than needed but the right hand side is a constant this way */ - if(dev > ((sizeof(dev_tab)/sizeof(struct devsw)) << 8) + 255) + if(dev > ((sizeof(dev_tab)/sizeof(struct devsw)) << 8) - 1) return false; else return true; diff --git a/Kernel/platform-px4plus/devices.c b/Kernel/platform-px4plus/devices.c index fbd7369a..a6fd8a34 100644 --- a/Kernel/platform-px4plus/devices.c +++ b/Kernel/platform-px4plus/devices.c @@ -29,7 +29,7 @@ bool validdev(uint16_t dev) { /* This is a bit uglier than needed but the right hand side is a constant this way */ - if(dev > ((sizeof(dev_tab)/sizeof(struct devsw)) << 8) + 255) + if(dev > ((sizeof(dev_tab)/sizeof(struct devsw)) << 8) - 1) return false; else return true; diff --git a/Kernel/platform-socz80/devices.c b/Kernel/platform-socz80/devices.c index cdf1ef8e..2366f0c9 100644 --- a/Kernel/platform-socz80/devices.c +++ b/Kernel/platform-socz80/devices.c @@ -36,7 +36,7 @@ bool validdev(uint16_t dev) { /* This is a bit uglier than needed but the right hand side is a constant this way */ - if(dev > ((sizeof(dev_tab)/sizeof(struct devsw)) << 8) + 255) + if(dev > ((sizeof(dev_tab)/sizeof(struct devsw)) << 8) - 1) return false; else return true; diff --git a/Kernel/platform-tgl6502/devices.c b/Kernel/platform-tgl6502/devices.c index 614690bf..994f5f94 100644 --- a/Kernel/platform-tgl6502/devices.c +++ b/Kernel/platform-tgl6502/devices.c @@ -27,7 +27,7 @@ bool validdev(uint16_t dev) { /* This is a bit uglier than needed but the right hand side is a constant this way */ - if(dev > ((sizeof(dev_tab)/sizeof(struct devsw)) << 8) + 255) + if(dev > ((sizeof(dev_tab)/sizeof(struct devsw)) << 8) - 1) return false; else return true; diff --git a/Kernel/platform-trs80/devices.c b/Kernel/platform-trs80/devices.c index 1b804020..3c718856 100644 --- a/Kernel/platform-trs80/devices.c +++ b/Kernel/platform-trs80/devices.c @@ -35,7 +35,7 @@ bool validdev(uint16_t dev) { /* This is a bit uglier than needed but the right hand side is a constant this way */ - if(dev > ((sizeof(dev_tab)/sizeof(struct devsw)) << 8) + 255) + if(dev > ((sizeof(dev_tab)/sizeof(struct devsw)) << 8) - 1) return false; else return true; diff --git a/Kernel/platform-ubee/devices.c b/Kernel/platform-ubee/devices.c index 7d4f7ca8..50f30698 100644 --- a/Kernel/platform-ubee/devices.c +++ b/Kernel/platform-ubee/devices.c @@ -27,7 +27,7 @@ bool validdev(uint16_t dev) { /* This is a bit uglier than needed but the right hand side is a constant this way */ - if(dev > ((sizeof(dev_tab)/sizeof(struct devsw)) << 8) + 255) + if(dev > ((sizeof(dev_tab)/sizeof(struct devsw)) << 8) - 1) return false; else return true; diff --git a/Kernel/platform-v65/devices.c b/Kernel/platform-v65/devices.c index fe94a0b5..8f2563d7 100644 --- a/Kernel/platform-v65/devices.c +++ b/Kernel/platform-v65/devices.c @@ -27,7 +27,7 @@ bool validdev(uint16_t dev) { /* This is a bit uglier than needed but the right hand side is a constant this way */ - if(dev > ((sizeof(dev_tab)/sizeof(struct devsw)) << 8) + 255) + if(dev > ((sizeof(dev_tab)/sizeof(struct devsw)) << 8) - 1) return false; else return true; diff --git a/Kernel/platform-v68-banked/devices.c b/Kernel/platform-v68-banked/devices.c index 3c1bef54..623668c7 100644 --- a/Kernel/platform-v68-banked/devices.c +++ b/Kernel/platform-v68-banked/devices.c @@ -28,7 +28,7 @@ bool validdev(uint16_t dev) { /* This is a bit uglier than needed but the right hand side is a constant this way */ - if(dev > ((sizeof(dev_tab)/sizeof(struct devsw)) << 8) + 255) + if(dev > ((sizeof(dev_tab)/sizeof(struct devsw)) << 8) - 1) return false; else return true; diff --git a/Kernel/platform-v68-softmmu/devices.c b/Kernel/platform-v68-softmmu/devices.c index 5c797330..42e71872 100644 --- a/Kernel/platform-v68-softmmu/devices.c +++ b/Kernel/platform-v68-softmmu/devices.c @@ -28,7 +28,7 @@ bool validdev(uint16_t dev) { /* This is a bit uglier than needed but the right hand side is a constant this way */ - if(dev > ((sizeof(dev_tab)/sizeof(struct devsw)) << 8) + 255) + if(dev > ((sizeof(dev_tab)/sizeof(struct devsw)) << 8) - 1) return false; else return true; diff --git a/Kernel/platform-v68/devices.c b/Kernel/platform-v68/devices.c index 3c1bef54..623668c7 100644 --- a/Kernel/platform-v68/devices.c +++ b/Kernel/platform-v68/devices.c @@ -28,7 +28,7 @@ bool validdev(uint16_t dev) { /* This is a bit uglier than needed but the right hand side is a constant this way */ - if(dev > ((sizeof(dev_tab)/sizeof(struct devsw)) << 8) + 255) + if(dev > ((sizeof(dev_tab)/sizeof(struct devsw)) << 8) - 1) return false; else return true; diff --git a/Kernel/platform-z80pack-lite/devices.c b/Kernel/platform-z80pack-lite/devices.c index d67f11aa..759b4c17 100644 --- a/Kernel/platform-z80pack-lite/devices.c +++ b/Kernel/platform-z80pack-lite/devices.c @@ -29,7 +29,7 @@ bool validdev(uint16_t dev) { /* This is a bit uglier than needed but the right hand side is a constant this way */ - if(dev > ((sizeof(dev_tab)/sizeof(struct devsw)) << 8) + 255) + if(dev > ((sizeof(dev_tab)/sizeof(struct devsw)) << 8) - 1) return false; else return true; diff --git a/Kernel/platform-z80pack/devices.c b/Kernel/platform-z80pack/devices.c index fb8b5634..9d3c0ed6 100644 --- a/Kernel/platform-z80pack/devices.c +++ b/Kernel/platform-z80pack/devices.c @@ -30,7 +30,7 @@ bool validdev(uint16_t dev) { /* This is a bit uglier than needed but the right hand side is a constant this way */ - if(dev > ((sizeof(dev_tab)/sizeof(struct devsw)) << 8) + 255) + if(dev > ((sizeof(dev_tab)/sizeof(struct devsw)) << 8) - 1) return false; else return true; diff --git a/Kernel/platform-z80pack32/devices.c b/Kernel/platform-z80pack32/devices.c index c60640f7..31151c65 100644 --- a/Kernel/platform-z80pack32/devices.c +++ b/Kernel/platform-z80pack32/devices.c @@ -28,7 +28,7 @@ bool validdev(uint16_t dev) { /* This is a bit uglier than needed but the right hand side is a constant this way */ - if(dev > ((sizeof(dev_tab)/sizeof(struct devsw)) << 8) + 255) + if(dev > ((sizeof(dev_tab)/sizeof(struct devsw)) << 8) - 1) return false; else return true; diff --git a/Kernel/platform-zeta-v2/devices.c b/Kernel/platform-zeta-v2/devices.c index 63bbb7d1..322c8af3 100644 --- a/Kernel/platform-zeta-v2/devices.c +++ b/Kernel/platform-zeta-v2/devices.c @@ -40,7 +40,7 @@ bool validdev(uint16_t dev) { /* This is a bit uglier than needed but the right hand side is a constant this way */ - if(dev > ((sizeof(dev_tab)/sizeof(struct devsw)) << 8) + 255) + if(dev > ((sizeof(dev_tab)/sizeof(struct devsw)) << 8) - 1) return false; else return true; diff --git a/Kernel/platform-zx128/devices.c b/Kernel/platform-zx128/devices.c index b8abe9ba..9b312258 100644 --- a/Kernel/platform-zx128/devices.c +++ b/Kernel/platform-zx128/devices.c @@ -43,7 +43,7 @@ bool validdev(uint16_t dev) { /* This is a bit uglier than needed but the right hand side is a constant this way */ - if(dev > ((sizeof(dev_tab)/sizeof(struct devsw)) << 8) + 255) + if(dev > ((sizeof(dev_tab)/sizeof(struct devsw)) << 8) - 1) return false; else return true;