Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp868605pxv; Wed, 14 Jul 2021 17:59:55 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxq2dA0iyEiAinzp2nM3IdO2Q74AgLE14vDtx3hqBDejYuFku+fR0lm4Un3WdV+sVunbBfy X-Received: by 2002:a05:6402:22a3:: with SMTP id cx3mr1687255edb.264.1626310795440; Wed, 14 Jul 2021 17:59:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626310795; cv=none; d=google.com; s=arc-20160816; b=Cl8Snn4bD5bvS7tP+GSE+bKXvCkrklyNouIfFaPwMSE53NrDZ25MdIKFp7adsvQ9f8 zpnvSMW0Y6iooZveGcdkLXhMbaaO42YBurTFWU99zsaWJphrJk5f1O8KzQFPOc8sK7fi FXR6x7D/6of70yMMjmf5+05QMkGCYWwc0L9YZEOFP5+FhiXwKyPqFAssBri2zhCSBXvk 1wmNEbOGU2icAkV3Yk4Co67Jba905eQdF0brabtWW/wNvSDjFjPKO0M6LkuEsAItJLUn HTJhmFRSxMp6d7vHJd9iUnll3jUQ8hkBsHNIbFR6jsZEMwpVk22D1rFuDW6ZXtZkMx8r uTBQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-disposition:mime-version:message-id :subject:cc:to:from:date:dkim-signature; bh=gSBGqDMM3Jz7qv5xcKdOnajx3PDMhN4qp53yDYdoaRU=; b=ipAzkwdasV1Zd+3/yxHVUtyhUsUulgpOyl3agJU6g2/YkXtHI4C3lKpstdwmAv1Yze KERa3g+54ErYpmD5JIauWdgNtIEDdfkbO8PFiVajQM8NRlMhfZhdcz/UFK4JrDhrYtEl lFU0GotmPvXvlat/3RPBGLWcGafshsZ8JshHm2vq14fDcVgPOeNyWWfE8rsGvblwVrhQ ZhoZBZ3InHsqM4eOlQwIXHnwa1km0Q7saf9B7a7zpsnSEjPV7/32Wk06B8baH1s/Xd0k FOXeq7q4LU+qb3K2U02wgJK30ewGS/9HkNk8v1JcYgCek4Ii7EqWt3gfFgh0UcG6s2us VAfA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=TZTYDeob; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id kx9si4507963ejc.502.2021.07.14.17.59.32; Wed, 14 Jul 2021 17:59:55 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=TZTYDeob; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231515AbhGOA7Y (ORCPT + 99 others); Wed, 14 Jul 2021 20:59:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37470 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231407AbhGOA7X (ORCPT ); Wed, 14 Jul 2021 20:59:23 -0400 Received: from mail-wr1-x42c.google.com (mail-wr1-x42c.google.com [IPv6:2a00:1450:4864:20::42c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 81D6EC06175F for ; Wed, 14 Jul 2021 17:56:30 -0700 (PDT) Received: by mail-wr1-x42c.google.com with SMTP id f9so5406831wrq.11 for ; Wed, 14 Jul 2021 17:56:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:mime-version:content-disposition; bh=gSBGqDMM3Jz7qv5xcKdOnajx3PDMhN4qp53yDYdoaRU=; b=TZTYDeobReI0lDgoPR6N8gFO8LN1w4DsdXGUhDLn1nrJzQf+Xs0tP0mW0cLjRVIM+G G90WjIGjw12EZiffyjbsbkl186cn8MzGRF6nbrGbScN78/O5Spu7AWkA6w6AQplLRcrA l+FSln1FteHsKdHKBjJZZf9TCcXPDmDARD0FKHAOCVXKhEEf3Xq0R7Wrw9+yAKghlIhd af7FAPq5NPYqnLsTqsws7qTZ60EkSO5FrF2uXWQ/6F2JVbv7Hir8BGDkw2tysLmq/1/4 K1SVZPIytbtXqlbFBjK2cgBMiF4fuqPxYbPw6TbjbKPcVmpw2tdvci7BCay9hs2VNnq7 CfCg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition; bh=gSBGqDMM3Jz7qv5xcKdOnajx3PDMhN4qp53yDYdoaRU=; b=KcxI7LheYyHAQVyxZ3hcKozWzg0LT4zdCoLhRTbJr2Kwge+DirhQST3VIbq2gnWryL i3aLte6qFBU8tNEFHgSVrO3+agZX7LASd3wfffQsfALTWznWHEJ5ZdRQiDqCvyak5mIm h4AATZM4xUP3vYo7Y4TD2C3k2AhJx6FW3S5Cjh1lWrBM44g7GzLvqV2lUaLQxcIGL8cZ SaBzd24FX3I8PREOOXaf3Yf3SseFc5EVfPCEfT24XCkjDiHfHH6YshdB3Rj3fVtwAhsH eK5UfQAX7tzovjqGvx4Ync4yn9LGti+IjE197ik6XaD/JD3HPoZrM80qZNvY3xZJS53y MMtw== X-Gm-Message-State: AOAM530yRXB+RYPftlt+inBoJrBWdQT6A3NxtPNUSSinjxtZN579iUCS xiXW5SrVK8RqXodwpmT8GejE9uuLCGM= X-Received: by 2002:adf:a183:: with SMTP id u3mr897426wru.175.1626310589080; Wed, 14 Jul 2021 17:56:29 -0700 (PDT) Received: from pc ([196.235.28.219]) by smtp.gmail.com with ESMTPSA id p2sm3352888wmg.6.2021.07.14.17.56.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Jul 2021 17:56:28 -0700 (PDT) Date: Thu, 15 Jul 2021 01:56:25 +0100 From: Salah Triki To: perex@perex.cz, tiwai@suse.com Cc: alsa-devel@alsa-project.org, linux-kernel@vger.kernel.org Subject: [PATCH] sound: usb: line6: free allocated urbs on failure Message-ID: <20210715005625.GA1997259@pc> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Free allocated urbs on failure in order to prevent memory leaks. Signed-off-by: Salah Triki --- sound/usb/line6/capture.c | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/sound/usb/line6/capture.c b/sound/usb/line6/capture.c index 970c9bdce0b2..345b75ede5d5 100644 --- a/sound/usb/line6/capture.c +++ b/sound/usb/line6/capture.c @@ -258,6 +258,7 @@ int line6_create_audio_in_urbs(struct snd_line6_pcm *line6pcm) { struct usb_line6 *line6 = line6pcm->line6; int i; + int ret; line6pcm->in.urbs = kcalloc(line6->iso_buffers, sizeof(struct urb *), GFP_KERNEL); @@ -272,8 +273,10 @@ int line6_create_audio_in_urbs(struct snd_line6_pcm *line6pcm) urb = line6pcm->in.urbs[i] = usb_alloc_urb(LINE6_ISO_PACKETS, GFP_KERNEL); - if (urb == NULL) - return -ENOMEM; + if (urb == NULL) { + ret = -ENOMEM; + goto enomem; + } urb->dev = line6->usbdev; urb->pipe = @@ -286,9 +289,20 @@ int line6_create_audio_in_urbs(struct snd_line6_pcm *line6pcm) urb->interval = LINE6_ISO_INTERVAL; urb->error_count = 0; urb->complete = audio_in_callback; - if (usb_urb_ep_type_check(urb)) - return -EINVAL; + if (usb_urb_ep_type_check(urb)) { + ret = -EINVAL; + goto einval; + } } return 0; + +enomem: + i--; + +einval: + while (i >= 0) + usb_free_urb(line6pcm->in.urbs[i--]); + + return ret; } -- 2.25.1