Commit d4c08afa authored by Julian Wiedmann's avatar Julian Wiedmann Committed by David S. Miller

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: default avatarJulian Wiedmann <jwi@linux.ibm.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent c3b2218d
...@@ -4320,18 +4320,13 @@ static int qeth_snmp_command_cb(struct qeth_card *card, ...@@ -4320,18 +4320,13 @@ static int qeth_snmp_command_cb(struct qeth_card *card,
return -ENOSPC; return -ENOSPC;
} }
QETH_CARD_TEXT_(card, 4, "snore%i", 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", QETH_CARD_TEXT_(card, 4, "sseqn%i",
cmd->data.setadapterparms.hdr.seq_no); cmd->data.setadapterparms.hdr.seq_no);
/*copy entries to user buffer*/ /*copy entries to user buffer*/
memcpy(qinfo->udata + qinfo->udata_offset, snmp_data, data_len); memcpy(qinfo->udata + qinfo->udata_offset, snmp_data, data_len);
qinfo->udata_offset += 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 < if (cmd->data.setadapterparms.hdr.seq_no <
cmd->data.setadapterparms.hdr.used_total) cmd->data.setadapterparms.hdr.used_total)
return 1; return 1;
...@@ -4340,9 +4335,8 @@ static int qeth_snmp_command_cb(struct qeth_card *card, ...@@ -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) 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_cmd_buffer *iob;
struct qeth_ipa_cmd *cmd;
struct qeth_snmp_ureq *ureq;
unsigned int req_len; unsigned int req_len;
struct qeth_arp_query_info qinfo = {0, }; struct qeth_arp_query_info qinfo = {0, };
int rc = 0; int rc = 0;
...@@ -4356,34 +4350,28 @@ static int qeth_snmp_command(struct qeth_card *card, char __user *udata) ...@@ -4356,34 +4350,28 @@ static int qeth_snmp_command(struct qeth_card *card, char __user *udata)
IS_LAYER3(card)) IS_LAYER3(card))
return -EOPNOTSUPP; return -EOPNOTSUPP;
/* skip 4 bytes (data_len struct member) to get req_len */ ureq = (struct qeth_snmp_ureq __user *) udata;
if (copy_from_user(&req_len, udata + sizeof(int), sizeof(int))) 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; 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); qinfo.udata = kzalloc(qinfo.udata_len, GFP_KERNEL);
if (!qinfo.udata) { if (!qinfo.udata) {
kfree(ureq); qeth_put_cmd(iob);
return -ENOMEM; return -ENOMEM;
} }
qinfo.udata_offset = sizeof(struct qeth_snmp_ureq_hdr); 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); rc = qeth_send_ipa_cmd(card, iob, qeth_snmp_command_cb, &qinfo);
if (rc) if (rc)
QETH_DBF_MESSAGE(2, "SNMP command failed on device %x: (%#x)\n", 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) ...@@ -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)) if (copy_to_user(udata, qinfo.udata, qinfo.udata_len))
rc = -EFAULT; rc = -EFAULT;
} }
out:
kfree(ureq);
kfree(qinfo.udata); kfree(qinfo.udata);
return rc; return rc;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment