From mboxrd@z Thu Jan 1 00:00:00 1970 From: Valentine Barshak Subject: Re: [PATCH] USB: net: Fix asix read transfer buffer allocations. Date: Tue, 23 Oct 2007 21:20:18 +0400 Message-ID: <471E2D52.5060404@ru.mvista.com> References: <20071022155053.GA28526@ru.mvista.com> <200710221929.04035.oliver@neukum.org> <471CF893.3050605@ru.mvista.com> <200710231900.14696.netdev@axxeo.de> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Cc: netdev@vger.kernel.org, Oliver Neukum , linux-usb-devel@lists.sourceforge.net To: Ingo Oeser Return-path: In-Reply-To: <200710231900.14696.netdev@axxeo.de> List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: linux-usb-devel-bounces@lists.sourceforge.net Errors-To: linux-usb-devel-bounces@lists.sourceforge.net List-Id: netdev.vger.kernel.org Ingo Oeser wrote: > Valentine Barshak schrieb: >> Oliver Neukum wrote: >>> Am Montag 22 Oktober 2007 schrieb Valentine Barshak: >>>> static int asix_mdio_read(struct net_device *netdev, int phy_id, int loc) >>>> { >>>> struct usbnet *dev = netdev_priv(netdev); >>>> + void *buf; >>>> u16 res; >>>> >>>> mutex_lock(&dev->phy_mutex); >>>> asix_set_sw_mii(dev); >>>> + >>>> + buf = kmalloc(2, GFP_KERNEL); >>> This is done under lock. Can you allocate the buffer once and reuse it? >> I think we can use 2 bytes of the usbnet data buffer for this. >> I'll submit a new patch soon. > > If this cannot be done for some reason, then you can at least kmalloc() before > you do "mutex_lock(&dev->phy_mutex);" and kfree() after you did > "mutex_unlock(&dev->phy_mutex);" > > The reason to can do this, is that "buf" has a life time limited to this function. > > The reason you should do this, is that kmalloc(, GFP_KERNEL) is allowed to sleep, > which will block the mutex for that time. While this is technically ok, > since mutexes can sleep, it is not desireable, since other users of that mutex > are blocked until the allocation is done. > > If you are able to implement the "2 bytes of usbnet data buffer" version, > please ignore that mail :-) > > > Best Regards > > Ingo Oeser Looks like we cannot use usbnet data buffer for read transfers either, because it's just a part of the usbnet structure and we may still lose data while invalidating cache the same way we do using buffers on stack. Allocating a permanent buffer for phy transfer needs more driver changes: we should add unbind finction to the device_info for all asix devices to deallocate the buffer at exit. And we still need to allocate buffers for other transfers dynamically, so having just one permanent buffer for phy doesn't help much. I've reworked the original patch a bit: moved kmalloc out of the phy_mutex and added more clean-ups. Will submit shortly. Thanks, Valentine. ------------------------------------------------------------------------- This SF.net email is sponsored by: Splunk Inc. Still grepping through log files to find problems? Stop. Now Search log events and configuration files using AJAX and a browser. Download your FREE copy of Splunk now >> http://get.splunk.com/ _______________________________________________ linux-usb-devel@lists.sourceforge.net To unsubscribe, use the last form field at: https://lists.sourceforge.net/lists/listinfo/linux-usb-devel