mirror of
https://git.FreeBSD.org/src.git
synced 2024-12-04 09:09:56 +00:00
mprutil: "fix user reply buffer (64)..." warnings
Depending on the card's firmware version, it may return different length responses for MPI2_FUNCTION_IOC_FACTS. But the first part of the response contains the length of the rest, so query it first to get the length and then use that to size the buffer for the full response. Also, correctly zero-initialize MPI2_IOC_FACTS_REQUEST. It only worked by luck before. PR: 264848 Reported by: Julien Cigar <julien@perdition.city> MFC after: 1 week Sponsored by: Axcient Reviewed by: scottl, imp Differential Revision: https://reviews.freebsd.org/D38739
This commit is contained in:
parent
fb619c94c6
commit
7d154c4dc6
@ -1871,7 +1871,7 @@ mpr_setup_sysctl(struct mpr_softc *sc)
|
||||
|
||||
SYSCTL_ADD_STRING(sysctl_ctx, SYSCTL_CHILDREN(sysctl_tree),
|
||||
OID_AUTO, "msg_version", CTLFLAG_RD, sc->msg_version,
|
||||
strlen(sc->msg_version), "message interface version");
|
||||
strlen(sc->msg_version), "message interface version (deprecated)");
|
||||
|
||||
SYSCTL_ADD_INT(sysctl_ctx, SYSCTL_CHILDREN(sysctl_tree),
|
||||
OID_AUTO, "io_cmds_active", CTLFLAG_RD,
|
||||
|
@ -852,7 +852,7 @@ mpr_user_pass_thru(struct mpr_softc *sc, mpr_pass_thru_t *data)
|
||||
rpl = (MPI2_DEFAULT_REPLY *)cm->cm_reply;
|
||||
sz = rpl->MsgLength * 4;
|
||||
|
||||
if (sz > data->ReplySize) {
|
||||
if (bootverbose && sz > data->ReplySize) {
|
||||
mpr_printf(sc, "%s: user reply buffer (%d) "
|
||||
"smaller than returned buffer (%d)\n",
|
||||
__func__, data->ReplySize, sz);
|
||||
@ -1077,7 +1077,7 @@ mpr_user_pass_thru(struct mpr_softc *sc, mpr_pass_thru_t *data)
|
||||
rpl = (MPI2_DEFAULT_REPLY *)cm->cm_reply;
|
||||
sz = rpl->MsgLength * 4;
|
||||
|
||||
if (sz > data->ReplySize) {
|
||||
if (bootverbose && sz > data->ReplySize) {
|
||||
mpr_printf(sc, "%s: user reply buffer (%d) smaller "
|
||||
"than returned buffer (%d)\n", __func__,
|
||||
data->ReplySize, sz);
|
||||
|
@ -1719,7 +1719,7 @@ mps_setup_sysctl(struct mps_softc *sc)
|
||||
|
||||
SYSCTL_ADD_STRING(sysctl_ctx, SYSCTL_CHILDREN(sysctl_tree),
|
||||
OID_AUTO, "msg_version", CTLFLAG_RD, sc->msg_version,
|
||||
strlen(sc->msg_version), "message interface version");
|
||||
strlen(sc->msg_version), "message interface version (deprecated)");
|
||||
|
||||
SYSCTL_ADD_INT(sysctl_ctx, SYSCTL_CHILDREN(sysctl_tree),
|
||||
OID_AUTO, "io_cmds_active", CTLFLAG_RD,
|
||||
|
@ -851,7 +851,7 @@ mps_user_pass_thru(struct mps_softc *sc, mps_pass_thru_t *data)
|
||||
rpl = (MPI2_DEFAULT_REPLY *)cm->cm_reply;
|
||||
sz = rpl->MsgLength * 4;
|
||||
|
||||
if (sz > data->ReplySize) {
|
||||
if (bootverbose && sz > data->ReplySize) {
|
||||
mps_printf(sc, "%s: user reply buffer (%d) "
|
||||
"smaller than returned buffer (%d)\n",
|
||||
__func__, data->ReplySize, sz);
|
||||
@ -1005,7 +1005,7 @@ mps_user_pass_thru(struct mps_softc *sc, mps_pass_thru_t *data)
|
||||
rpl = (MPI2_DEFAULT_REPLY *)cm->cm_reply;
|
||||
sz = rpl->MsgLength * 4;
|
||||
|
||||
if (sz > data->ReplySize) {
|
||||
if (bootverbose && sz > data->ReplySize) {
|
||||
mps_printf(sc, "%s: user reply buffer (%d) smaller "
|
||||
"than returned buffer (%d)\n", __func__,
|
||||
data->ReplySize, sz);
|
||||
|
@ -721,25 +721,39 @@ mps_pass_command(int fd, void *req, uint32_t req_len, void *reply,
|
||||
return (0);
|
||||
}
|
||||
|
||||
/* Return the length in bytes of the device's MPI2_IOC_FACTS reply */
|
||||
static size_t
|
||||
mps_get_ioc_factslen(int fd)
|
||||
{
|
||||
MPI2_IOC_FACTS_REQUEST req;
|
||||
const size_t factslen = 4;
|
||||
char factsbuf[4] = {0};
|
||||
MPI2_IOC_FACTS_REPLY *facts = (MPI2_IOC_FACTS_REPLY*)factsbuf;
|
||||
int error;
|
||||
|
||||
bzero(&req, sizeof(req));
|
||||
req.Function = MPI2_FUNCTION_IOC_FACTS;
|
||||
error = mps_pass_command(fd, &req, sizeof(MPI2_IOC_FACTS_REQUEST),
|
||||
factsbuf, factslen, NULL, 0, NULL, 0, 10);
|
||||
|
||||
if (error)
|
||||
return (0);
|
||||
|
||||
/* The card's response is measured in dwords */
|
||||
return (facts->MsgLength * 4);
|
||||
}
|
||||
|
||||
MPI2_IOC_FACTS_REPLY *
|
||||
mps_get_iocfacts(int fd)
|
||||
{
|
||||
MPI2_IOC_FACTS_REPLY *facts;
|
||||
MPI2_IOC_FACTS_REQUEST req;
|
||||
char msgver[8], sysctlname[128];
|
||||
size_t len, factslen;
|
||||
size_t factslen;
|
||||
int error;
|
||||
|
||||
snprintf(sysctlname, sizeof(sysctlname), "dev.%s.%d.msg_version",
|
||||
is_mps ? "mps" : "mpr", mps_unit);
|
||||
|
||||
factslen = sizeof(MPI2_IOC_FACTS_REPLY);
|
||||
len = sizeof(msgver);
|
||||
error = sysctlbyname(sysctlname, msgver, &len, NULL, 0);
|
||||
if (error == 0) {
|
||||
if (strncmp(msgver, "2.6", sizeof(msgver)) == 0)
|
||||
factslen += 4;
|
||||
}
|
||||
factslen = mps_get_ioc_factslen(fd);
|
||||
if (factslen == 0)
|
||||
return (NULL);
|
||||
|
||||
facts = malloc(factslen);
|
||||
if (facts == NULL) {
|
||||
@ -747,7 +761,7 @@ mps_get_iocfacts(int fd)
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
bzero(&req, factslen);
|
||||
bzero(&req, sizeof(req));
|
||||
req.Function = MPI2_FUNCTION_IOC_FACTS;
|
||||
|
||||
#if 1
|
||||
|
Loading…
Reference in New Issue
Block a user