lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20130730140152.GF27962@kroah.com>
Date:	Tue, 30 Jul 2013 07:01:52 -0700
From:	Greg KH <gregkh@...uxfoundation.org>
To:	Hayes Wang <hayeswang@...ltek.com>
Cc:	netdev@...r.kernel.org, linux-kernel@...r.kernel.org,
	linux-usb@...r.kernel.org, nic_swsd@...ltek.com
Subject: Re: [PATCH v3 2/3] net/usb/r8152: replace USB buffer from stack to
 DMA-able

On Tue, Jul 30, 2013 at 04:28:55PM +0800, Hayes Wang wrote:
> Allocate the required transfer buffer for usb_control_msg.
> 
> Signed-off-by: Hayes Wang <hayeswang@...ltek.com>
> ---
>  drivers/net/usb/r8152.c | 91 +++++++++++++++++++++++++++++++++++--------------
>  1 file changed, 66 insertions(+), 25 deletions(-)
> 
> diff --git a/drivers/net/usb/r8152.c b/drivers/net/usb/r8152.c
> index ee13f9e..93a7baa 100644
> --- a/drivers/net/usb/r8152.c
> +++ b/drivers/net/usb/r8152.c
> @@ -282,6 +282,8 @@ enum rtl_register_content {
>  #define RTL8152_RMS		(VLAN_ETH_FRAME_LEN + VLAN_HLEN)
>  #define RTL8152_TX_TIMEOUT	(HZ)
>  
> +#define RTL8152_MAX_TRANSFER_SIZE	8
> +
>  /* rtl8152 flags */
>  enum rtl8152_flags {
>  	RTL8152_UNPLUG = 0,
> @@ -324,8 +326,10 @@ struct r8152 {
>  	struct sk_buff *tx_skb, *rx_skb;
>  	struct delayed_work schedule;
>  	struct mii_if_info mii;
> +	struct mutex transfer_mutex;
>  	u32 msg_enable;
>  	u16 ocp_base;
> +	u8 *transfer_buf;
>  	u8 version;
>  	u8 speed;
>  };
> @@ -344,17 +348,59 @@ static const int multicast_filter_limit = 32;
>  static
>  int get_registers(struct r8152 *tp, u16 value, u16 index, u16 size, void *data)
>  {
> -	return usb_control_msg(tp->udev, usb_rcvctrlpipe(tp->udev, 0),
> +	int ret;
> +	void *tmp;
> +
> +	if (size > RTL8152_MAX_TRANSFER_SIZE || !tp->transfer_buf) {
> +		tmp = kmalloc(size, GFP_KERNEL);
> +		if (!tmp)
> +			return -ENOMEM;
> +	} else {
> +		mutex_lock(&tp->transfer_mutex);
> +		tmp = tp->transfer_buf;
> +	}
> +
> +	ret = usb_control_msg(tp->udev, usb_rcvctrlpipe(tp->udev, 0),
>  			       RTL8152_REQ_GET_REGS, RTL8152_REQT_READ,
> -			       value, index, data, size, 500);
> +			       value, index, tmp, size, 500);

Same here, no need for your "transfer buf" structure, just always
kmalloc the data, copy it in, and make the call.  It's _really_ slow
anyway, you will never notice any speed overhead by doing this.

thanks,

greg k-h
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ