Changeset View
Changeset View
Standalone View
Standalone View
sys/dev/asmc/asmc.c
Show First 20 Lines • Show All 957 Lines • ▼ Show 20 Lines | asmc_fan_getvalue(device_t dev, const char *key, int fan) | ||||
if (asmc_key_read(dev, fankey, buf, sizeof buf) < 0) | if (asmc_key_read(dev, fankey, buf, sizeof buf) < 0) | ||||
return (-1); | return (-1); | ||||
speed = (buf[0] << 6) | (buf[1] >> 2); | speed = (buf[0] << 6) | (buf[1] >> 2); | ||||
return (speed); | return (speed); | ||||
} | } | ||||
static char* | static char* | ||||
asmc_fan_getstring(device_t dev, const char *key, int fan) | asmc_fan_getstring(device_t dev, const char *key, int fan, uint8_t *buf, int buflen) | ||||
ed: Maybe use `size_t buflen`? If `asmc_key_read()` uses `int` anyway, just leave it the way it is. | |||||
uqsAuthorUnsubmitted Not Done Inline ActionsYeah, I of course had size_t first, but realistically a char would suffice. I wanted to keep it as a 32bit int for the minor savings for LP64 platforms. http://bxr.su/FreeBSD/sys/dev/asmc/asmc.c#717 asmc_key_read(device_t dev, const char *key, uint8_t *buf, uint8_t len) so maybe use uint8_t as well? uqs: Yeah, I of course had size_t first, but realistically a char would suffice. I wanted to keep it… | |||||
{ | { | ||||
uint8_t buf[16]; | |||||
char fankey[5]; | char fankey[5]; | ||||
char* desc; | char* desc; | ||||
snprintf(fankey, sizeof(fankey), key, fan); | snprintf(fankey, sizeof(fankey), key, fan); | ||||
if (asmc_key_read(dev, fankey, buf, sizeof buf) < 0) | if (asmc_key_read(dev, fankey, buf, buflen) < 0) | ||||
return (NULL); | return (NULL); | ||||
desc = buf+4; | desc = buf+4; | ||||
return (desc); | return (desc); | ||||
} | } | ||||
static int | static int | ||||
asmc_fan_setvalue(device_t dev, const char *key, int fan, int speed) | asmc_fan_setvalue(device_t dev, const char *key, int fan, int speed) | ||||
Show All 25 Lines | asmc_mb_sysctl_fanspeed(SYSCTL_HANDLER_ARGS) | ||||
error = sysctl_handle_int(oidp, &v, 0, req); | error = sysctl_handle_int(oidp, &v, 0, req); | ||||
return (error); | return (error); | ||||
} | } | ||||
static int | static int | ||||
asmc_mb_sysctl_fanid(SYSCTL_HANDLER_ARGS) | asmc_mb_sysctl_fanid(SYSCTL_HANDLER_ARGS) | ||||
{ | { | ||||
uint8_t buf[16]; | |||||
device_t dev = (device_t) arg1; | device_t dev = (device_t) arg1; | ||||
int fan = arg2; | int fan = arg2; | ||||
int error = true; | int error = true; | ||||
char* desc; | char* desc; | ||||
desc = asmc_fan_getstring(dev, ASMC_KEY_FANID, fan); | desc = asmc_fan_getstring(dev, ASMC_KEY_FANID, fan, buf, sizeof buf); | ||||
edUnsubmitted Done Inline Actionssizeof(buf) per style(9). ed: `sizeof(buf)` per `style(9)`. | |||||
if (desc != NULL) | if (desc != NULL) | ||||
error = sysctl_handle_string(oidp, desc, 0, req); | error = sysctl_handle_string(oidp, desc, 0, req); | ||||
return (error); | return (error); | ||||
} | } | ||||
static int | static int | ||||
▲ Show 20 Lines • Show All 314 Lines • Show Last 20 Lines |
Maybe use size_t buflen? If asmc_key_read() uses int anyway, just leave it the way it is.