forked from luck/tmp_suning_uos_patched
s390/qeth: streamline SNMP cmd code
Apply some cleanups to qeth_snmp_command() and its callback: 1. when accessing the user data, use the proper struct instead of hard-coded offsets. Also copy the request data straight into the allocated cmd, skipping the extra memdup_user() to a tmp buffer. 2. capping the request length is no longer needed, the same check gets applied at a base level in qeth_alloc_cmd(). 3. clean up some duplicated (and misindented) trace statements. Signed-off-by: Julian Wiedmann <jwi@linux.ibm.com> Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
parent
c3b2218d31
commit
d4c08afafa
|
@ -4320,18 +4320,13 @@ static int qeth_snmp_command_cb(struct qeth_card *card,
|
|||
return -ENOSPC;
|
||||
}
|
||||
QETH_CARD_TEXT_(card, 4, "snore%i",
|
||||
cmd->data.setadapterparms.hdr.used_total);
|
||||
cmd->data.setadapterparms.hdr.used_total);
|
||||
QETH_CARD_TEXT_(card, 4, "sseqn%i",
|
||||
cmd->data.setadapterparms.hdr.seq_no);
|
||||
cmd->data.setadapterparms.hdr.seq_no);
|
||||
/*copy entries to user buffer*/
|
||||
memcpy(qinfo->udata + qinfo->udata_offset, snmp_data, data_len);
|
||||
qinfo->udata_offset += data_len;
|
||||
|
||||
/* check if all replies received ... */
|
||||
QETH_CARD_TEXT_(card, 4, "srtot%i",
|
||||
cmd->data.setadapterparms.hdr.used_total);
|
||||
QETH_CARD_TEXT_(card, 4, "srseq%i",
|
||||
cmd->data.setadapterparms.hdr.seq_no);
|
||||
if (cmd->data.setadapterparms.hdr.seq_no <
|
||||
cmd->data.setadapterparms.hdr.used_total)
|
||||
return 1;
|
||||
|
@ -4340,9 +4335,8 @@ static int qeth_snmp_command_cb(struct qeth_card *card,
|
|||
|
||||
static int qeth_snmp_command(struct qeth_card *card, char __user *udata)
|
||||
{
|
||||
struct qeth_snmp_ureq __user *ureq;
|
||||
struct qeth_cmd_buffer *iob;
|
||||
struct qeth_ipa_cmd *cmd;
|
||||
struct qeth_snmp_ureq *ureq;
|
||||
unsigned int req_len;
|
||||
struct qeth_arp_query_info qinfo = {0, };
|
||||
int rc = 0;
|
||||
|
@ -4356,34 +4350,28 @@ static int qeth_snmp_command(struct qeth_card *card, char __user *udata)
|
|||
IS_LAYER3(card))
|
||||
return -EOPNOTSUPP;
|
||||
|
||||
/* skip 4 bytes (data_len struct member) to get req_len */
|
||||
if (copy_from_user(&req_len, udata + sizeof(int), sizeof(int)))
|
||||
ureq = (struct qeth_snmp_ureq __user *) udata;
|
||||
if (get_user(qinfo.udata_len, &ureq->hdr.data_len) ||
|
||||
get_user(req_len, &ureq->hdr.req_len))
|
||||
return -EFAULT;
|
||||
|
||||
iob = qeth_get_adapter_cmd(card, IPA_SETADP_SET_SNMP_CONTROL, req_len);
|
||||
if (!iob)
|
||||
return -ENOMEM;
|
||||
|
||||
if (copy_from_user(&__ipa_cmd(iob)->data.setadapterparms.data.snmp,
|
||||
&ureq->cmd, req_len)) {
|
||||
qeth_put_cmd(iob);
|
||||
return -EFAULT;
|
||||
if (req_len + offsetof(struct qeth_ipacmd_setadpparms, data) +
|
||||
offsetof(struct qeth_ipa_cmd, data) + IPA_PDU_HEADER_SIZE >
|
||||
QETH_BUFSIZE)
|
||||
return -EINVAL;
|
||||
ureq = memdup_user(udata, req_len + sizeof(struct qeth_snmp_ureq_hdr));
|
||||
if (IS_ERR(ureq)) {
|
||||
QETH_CARD_TEXT(card, 2, "snmpnome");
|
||||
return PTR_ERR(ureq);
|
||||
}
|
||||
qinfo.udata_len = ureq->hdr.data_len;
|
||||
|
||||
qinfo.udata = kzalloc(qinfo.udata_len, GFP_KERNEL);
|
||||
if (!qinfo.udata) {
|
||||
kfree(ureq);
|
||||
qeth_put_cmd(iob);
|
||||
return -ENOMEM;
|
||||
}
|
||||
qinfo.udata_offset = sizeof(struct qeth_snmp_ureq_hdr);
|
||||
|
||||
iob = qeth_get_adapter_cmd(card, IPA_SETADP_SET_SNMP_CONTROL, req_len);
|
||||
if (!iob) {
|
||||
rc = -ENOMEM;
|
||||
goto out;
|
||||
}
|
||||
|
||||
cmd = __ipa_cmd(iob);
|
||||
memcpy(&cmd->data.setadapterparms.data.snmp, &ureq->cmd, req_len);
|
||||
rc = qeth_send_ipa_cmd(card, iob, qeth_snmp_command_cb, &qinfo);
|
||||
if (rc)
|
||||
QETH_DBF_MESSAGE(2, "SNMP command failed on device %x: (%#x)\n",
|
||||
|
@ -4392,8 +4380,7 @@ static int qeth_snmp_command(struct qeth_card *card, char __user *udata)
|
|||
if (copy_to_user(udata, qinfo.udata, qinfo.udata_len))
|
||||
rc = -EFAULT;
|
||||
}
|
||||
out:
|
||||
kfree(ureq);
|
||||
|
||||
kfree(qinfo.udata);
|
||||
return rc;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user