Fix off-by-one bugs.
Spotted by: rpaulo (on another review)
This commit is contained in:
parent
bf5182c099
commit
b25767bb39
@ -64,8 +64,6 @@ struct ds3231_softc {
|
||||
uint8_t sc_status;
|
||||
};
|
||||
|
||||
static int ds3231_sqw_freq[] = { 1, 1024, 4096, 8192 };
|
||||
|
||||
static void ds3231_start(void *);
|
||||
|
||||
static int
|
||||
@ -282,6 +280,7 @@ ds3231_bbsqw_sysctl(SYSCTL_HANDLER_ARGS)
|
||||
static int
|
||||
ds3231_sqw_freq_sysctl(SYSCTL_HANDLER_ARGS)
|
||||
{
|
||||
int ds3231_sqw_freq[] = { 1, 1024, 4096, 8192 };
|
||||
int error, freq, i, newf, tmp;
|
||||
struct ds3231_softc *sc;
|
||||
|
||||
@ -290,8 +289,8 @@ ds3231_sqw_freq_sysctl(SYSCTL_HANDLER_ARGS)
|
||||
if (error != 0)
|
||||
return (error);
|
||||
tmp = (sc->sc_ctrl & DS3231_CTRL_RS_MASK) >> DS3231_CTRL_RS_SHIFT;
|
||||
if (tmp > nitems(ds3231_sqw_freq))
|
||||
tmp = nitems(ds3231_sqw_freq);
|
||||
if (tmp >= nitems(ds3231_sqw_freq))
|
||||
tmp = nitems(ds3231_sqw_freq) - 1;
|
||||
freq = ds3231_sqw_freq[tmp];
|
||||
error = sysctl_handle_int(oidp, &freq, 0, req);
|
||||
if (error != 0 || req->newptr == NULL)
|
||||
|
@ -90,8 +90,6 @@ struct lm75_softc {
|
||||
uint32_t sc_conf;
|
||||
};
|
||||
|
||||
static int lm75_faults[4] = { 1, 2, 4, 6 };
|
||||
|
||||
/* Utility functions */
|
||||
static int lm75_conf_read(struct lm75_softc *);
|
||||
static int lm75_conf_write(struct lm75_softc *);
|
||||
@ -457,14 +455,15 @@ static int
|
||||
lm75_faults_sysctl(SYSCTL_HANDLER_ARGS)
|
||||
{
|
||||
device_t dev;
|
||||
int lm75_faults[] = { 1, 2, 4, 6 };
|
||||
int error, faults, i, newf, tmp;
|
||||
struct lm75_softc *sc;
|
||||
|
||||
dev = (device_t)arg1;
|
||||
sc = device_get_softc(dev);
|
||||
tmp = (sc->sc_conf & LM75_CONF_FAULT) >> LM75_CONF_FSHIFT;
|
||||
if (tmp > nitems(lm75_faults))
|
||||
tmp = nitems(lm75_faults);
|
||||
if (tmp >= nitems(lm75_faults))
|
||||
tmp = nitems(lm75_faults) - 1;
|
||||
faults = lm75_faults[tmp];
|
||||
|
||||
error = sysctl_handle_int(oidp, &faults, 0, req);
|
||||
|
Loading…
Reference in New Issue
Block a user