Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752331AbbKPLnn (ORCPT ); Mon, 16 Nov 2015 06:43:43 -0500 Received: from mailout3.w1.samsung.com ([210.118.77.13]:22017 "EHLO mailout3.w1.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751764AbbKPLnk (ORCPT ); Mon, 16 Nov 2015 06:43:40 -0500 X-AuditID: cbfec7f5-f794b6d000001495-a4-5649c16a9955 Subject: Re: [PATCH v5 4/7] usb: gadget: f_midi: fix leak on failed to enqueue out requests To: Felipe Ferreri Tonello , linux-usb@vger.kernel.org References: <1447177929-22252-1-git-send-email-eu@felipetonello.com> <1447177929-22252-5-git-send-email-eu@felipetonello.com> <56459FCF.8090409@samsung.com> <5649B92B.2010202@felipetonello.com> Cc: linux-kernel@vger.kernel.org, Felipe Balbi , Greg Kroah-Hartman , Clemens Ladisch From: Robert Baldyga Message-id: <5649C168.2030805@samsung.com> Date: Mon, 16 Nov 2015 12:43:36 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.3.0 MIME-version: 1.0 In-reply-to: <5649B92B.2010202@felipetonello.com> Content-type: text/plain; charset=windows-1252 Content-transfer-encoding: 7bit X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFrrKLMWRmVeSWpSXmKPExsVy+t/xK7pZBz3DDNa/YLY4eL/eYsmJh0wW nfPPsls0L17PZnF51xw2i0XLWpkd2Dzufn3I7vFjRT+zx/65a9g9jt/YzuTxeZNcAGsUl01K ak5mWWqRvl0CV8aB45YFbXwVb24uZWpgXMndxcjJISFgIvFl1zY2CFtM4sK99UA2F4eQwFJG iZc9S1khnGeMElMedrGCVAkLxEpsOHeXBcQWEfCRmLPmITNE0VFGicU7z7KDOMwCMxgl+nbc B5vLJqAjseX7BEYQm1dAS+L0q51MIDaLgKrEs7fbwSaJCkRITJzQwApRIyjxY/I9sDingKHE i87nQHM4gIbqSdy/qAUSZhaQl9i85i3zBEaBWUg6ZiFUzUJStYCReRWjaGppckFxUnqukV5x Ym5xaV66XnJ+7iZGSGB/3cG49JjVIUYBDkYlHt4TT9zDhFgTy4orcw8xSnAwK4nwfl3mGSbE m5JYWZValB9fVJqTWnyIUZqDRUmcd+au9yFCAumJJanZqakFqUUwWSYOTqkGxsNrrVwd7x2+ zPVyw3bnZ/+5kiVcNQ7d4Pl4wSnr/5UHVctf63LturC69cxWxSO8SVoeZqu9ONMeS7tzNP3d mHjhi2hg2UKz07H3HnGa8GiUxkj2Helaxbki67fOfBPF0wwnDx9jzF9U/+GC2VmJVVN4Z/Z7 ynR+bXzvYb+r+erTPd+n7+zUZFZiKc5INNRiLipOBADmr0+waAIAAA== Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1996 Lines: 52 On 11/16/2015 12:08 PM, Felipe Ferreri Tonello wrote: > Hi Robert, > > On 13/11/15 08:31, Robert Baldyga wrote: >> Hi Felipe, >> >> On 11/10/2015 06:52 PM, Felipe F. Tonello wrote: >>> This patch fixes a memory leak that occurs when an endpoint fails to enqueue >>> the request. If that happens the complete function will never be called, thus >>> never freeing the request. >>> >>> Signed-off-by: Felipe F. Tonello >>> --- >>> drivers/usb/gadget/function/f_midi.c | 1 + >>> 1 file changed, 1 insertion(+) >>> >>> diff --git a/drivers/usb/gadget/function/f_midi.c b/drivers/usb/gadget/function/f_midi.c >>> index f36db2d..76ea53c 100644 >>> --- a/drivers/usb/gadget/function/f_midi.c >>> +++ b/drivers/usb/gadget/function/f_midi.c >>> @@ -345,6 +345,7 @@ static int f_midi_set_alt(struct usb_function *f, unsigned intf, unsigned alt) >>> if (err) { >>> ERROR(midi, "%s queue req: %d\n", >>> midi->out_ep->name, err); >>> + free_ep_req(midi->out_ep, req); >>> } >>> } >>> >>> >> >> There is one more thing I haven't noticed before. We can have situation >> when all requests were allocated successfully, but their allocation >> failed. What we get then is set_alt() returning 0, while no request is >> allocated, hence the function is, in fact, inactive. > > Right. So in this case should we return some error? We can restrict the > function to work iff allocates the 'qlen' number of allocations, > otherwise returns an error and frees all other requests (IN and OUT). > Yes, IMO it's a proper solution. When user sets qlen to given value he expects that exact number of requests to be allocated and enqueued, and if we cannot do that we should consider this as an error. -- Best regards, Robert -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/