mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2024-10-02 07:04:24 +00:00
net: pegasus: Use the new usb control message API.
The old usb_control_msg() let the caller handle the error and also did not account for partial reads. Since these are now considered harmful, move the driver over to usb_control_msg_recv/send() calls. Added small note about why set_registers() can't be used to substitute set_register(). Signed-off-by: Petko Manolov <petko.manolov@konsulko.com> Acked-by: David S. Miller <davem@davemloft.net> Link: https://lore.kernel.org/r/20200927124909.16380-2-petko.manolov@konsulko.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
parent
b2a0f274e3
commit
fb58cf4f28
1 changed files with 15 additions and 46 deletions
|
@ -124,62 +124,31 @@ static void async_ctrl_callback(struct urb *urb)
|
|||
|
||||
static int get_registers(pegasus_t *pegasus, __u16 indx, __u16 size, void *data)
|
||||
{
|
||||
u8 *buf;
|
||||
int ret;
|
||||
|
||||
buf = kmalloc(size, GFP_NOIO);
|
||||
if (!buf)
|
||||
return -ENOMEM;
|
||||
|
||||
ret = usb_control_msg(pegasus->usb, usb_rcvctrlpipe(pegasus->usb, 0),
|
||||
PEGASUS_REQ_GET_REGS, PEGASUS_REQT_READ, 0,
|
||||
indx, buf, size, 1000);
|
||||
if (ret < 0)
|
||||
netif_dbg(pegasus, drv, pegasus->net,
|
||||
"%s returned %d\n", __func__, ret);
|
||||
else if (ret <= size)
|
||||
memcpy(data, buf, ret);
|
||||
kfree(buf);
|
||||
return ret;
|
||||
return usb_control_msg_recv(pegasus->usb, 0, PEGASUS_REQ_GET_REGS,
|
||||
PEGASUS_REQT_READ, 0, indx, data, size,
|
||||
1000, GFP_NOIO);
|
||||
}
|
||||
|
||||
static int set_registers(pegasus_t *pegasus, __u16 indx, __u16 size,
|
||||
const void *data)
|
||||
{
|
||||
u8 *buf;
|
||||
int ret;
|
||||
|
||||
buf = kmemdup(data, size, GFP_NOIO);
|
||||
if (!buf)
|
||||
return -ENOMEM;
|
||||
|
||||
ret = usb_control_msg(pegasus->usb, usb_sndctrlpipe(pegasus->usb, 0),
|
||||
PEGASUS_REQ_SET_REGS, PEGASUS_REQT_WRITE, 0,
|
||||
indx, buf, size, 100);
|
||||
if (ret < 0)
|
||||
netif_dbg(pegasus, drv, pegasus->net,
|
||||
"%s returned %d\n", __func__, ret);
|
||||
kfree(buf);
|
||||
return ret;
|
||||
return usb_control_msg_send(pegasus->usb, 0, PEGASUS_REQ_SET_REGS,
|
||||
PEGASUS_REQT_WRITE, 0, indx, data, size,
|
||||
1000, GFP_NOIO);
|
||||
}
|
||||
|
||||
/*
|
||||
* There is only one way to write to a single ADM8511 register and this is via
|
||||
* specific control request. 'data' is ignored by the device, but it is here to
|
||||
* not break the API.
|
||||
*/
|
||||
static int set_register(pegasus_t *pegasus, __u16 indx, __u8 data)
|
||||
{
|
||||
u8 *buf;
|
||||
int ret;
|
||||
void *buf = &data;
|
||||
|
||||
buf = kmemdup(&data, 1, GFP_NOIO);
|
||||
if (!buf)
|
||||
return -ENOMEM;
|
||||
|
||||
ret = usb_control_msg(pegasus->usb, usb_sndctrlpipe(pegasus->usb, 0),
|
||||
PEGASUS_REQ_SET_REG, PEGASUS_REQT_WRITE, data,
|
||||
indx, buf, 1, 1000);
|
||||
if (ret < 0)
|
||||
netif_dbg(pegasus, drv, pegasus->net,
|
||||
"%s returned %d\n", __func__, ret);
|
||||
kfree(buf);
|
||||
return ret;
|
||||
return usb_control_msg_send(pegasus->usb, 0, PEGASUS_REQ_SET_REG,
|
||||
PEGASUS_REQT_WRITE, data, indx, buf, 1,
|
||||
1000, GFP_NOIO);
|
||||
}
|
||||
|
||||
static int update_eth_regs_async(pegasus_t *pegasus)
|
||||
|
|
Loading…
Reference in a new issue