From patchwork Mon Mar 13 12:53:57 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johan Hovold X-Patchwork-Id: 9620789 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id CA72F60244 for ; Mon, 13 Mar 2017 12:57:03 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BB73926212 for ; Mon, 13 Mar 2017 12:57:03 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id AE96226E51; Mon, 13 Mar 2017 12:57:03 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.3 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM, T_DKIM_INVALID autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 26FDD26212 for ; Mon, 13 Mar 2017 12:57:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753149AbdCMM4A (ORCPT ); Mon, 13 Mar 2017 08:56:00 -0400 Received: from mail-lf0-f67.google.com ([209.85.215.67]:33965 "EHLO mail-lf0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750871AbdCMMyf (ORCPT ); Mon, 13 Mar 2017 08:54:35 -0400 Received: by mail-lf0-f67.google.com with SMTP id y193so11761111lfd.1; Mon, 13 Mar 2017 05:54:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=7UTiOVTZUMMnieKeYhzENcx9tB3J8B4rI2gtJmELQos=; b=gpv65Z/H3spjY6fVXSkVE/eR2/VE1tPabF4iUBCrBSHRmygMCyTkvqbGcUaFOym+jo Fbh6hUU1uAi81uWlYVkD+R8lXLYdbdhlN6uID4VSmQQnpburZV7kLsVW6I7QaZLsVRHL l4DgxIe041OVY5kwbPv8TozYPgssUD+mTdUDhdLO+t2nCLMUFJL3PvQgtXjrAsQA17zZ G4E/GKA7UbkbjD3v9LgjDfCuACpkxDjACo9kno5AUMaft52wmdTfZArA3q+5GVZToDtj e1LRxtENF0dWAhcmvnoPbHcvoxdVXT3FiIvbx4Xg1jTSt3RhQgqRIJlWuX8Dx0CdPYGD DUmQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=7UTiOVTZUMMnieKeYhzENcx9tB3J8B4rI2gtJmELQos=; b=jIE4qsNvnhU+682O188/4xbu++j7Nn/I9slxGgD5ThnHHWERjdwN/r9IPDA3A5TuGo OIA5lxVmoRMhRBA4bCxKk1wssrgLFBgtmAt1GNgSGMJJ6pljQh8Ju5h/K63YalPXvTuF 7qk4Ar7V0rKo8/lWRxwvagkpDmZtvMqFIxkA4rDLu+BPw9l0ZpFAcutMhw7bNwOFq+16 38G16qY+7+3xlVKtv5vAB3NGRsmFRRAwHNECL7QDG3yZUKh0TJdwVsQwDOk0L4QOOo/O LcaZ32rs79qotf12N0QsdAMh+EPFdrtqJ6JE4dg03upWhjdzaA49DhNrP9T/qAdd+ryt yjGw== X-Gm-Message-State: AMke39n7Ek7KzloleUZdDxj0keTGnWy69pxG5uro2b+TMgWm0atgSOdcKe1YYBiF75idSw== X-Received: by 10.25.25.14 with SMTP id 14mr8280109lfz.153.1489409672885; Mon, 13 Mar 2017 05:54:32 -0700 (PDT) Received: from xi.terra ([84.216.234.102]) by smtp.gmail.com with ESMTPSA id t19sm3539354ljd.30.2017.03.13.05.54.30 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 13 Mar 2017 05:54:31 -0700 (PDT) Received: from johan by xi.terra with local (Exim 4.89) (envelope-from ) id 1cnPUU-0007fB-9F; Mon, 13 Mar 2017 13:54:22 +0100 From: Johan Hovold To: Mauro Carvalho Chehab Cc: Hans Verkuil , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Johan Hovold , stable , Sri Deevi Subject: [PATCH 4/6] [media] cx231xx-audio: fix init error path Date: Mon, 13 Mar 2017 13:53:57 +0100 Message-Id: <20170313125359.29394-5-johan@kernel.org> X-Mailer: git-send-email 2.12.0 In-Reply-To: <20170313125359.29394-1-johan@kernel.org> References: <20170313125359.29394-1-johan@kernel.org> Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Make sure to release the snd_card also on a late allocation error. Fixes: e0d3bafd0258 ("V4L/DVB (10954): Add cx231xx USB driver") Cc: stable # 2.6.30 Cc: Sri Deevi Signed-off-by: Johan Hovold --- drivers/media/usb/cx231xx/cx231xx-audio.c | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/drivers/media/usb/cx231xx/cx231xx-audio.c b/drivers/media/usb/cx231xx/cx231xx-audio.c index cf80842dfa08..f3729d6eb46a 100644 --- a/drivers/media/usb/cx231xx/cx231xx-audio.c +++ b/drivers/media/usb/cx231xx/cx231xx-audio.c @@ -670,10 +670,8 @@ static int cx231xx_audio_init(struct cx231xx *dev) spin_lock_init(&adev->slock); err = snd_pcm_new(card, "Cx231xx Audio", 0, 0, 1, &pcm); - if (err < 0) { - snd_card_free(card); - return err; - } + if (err < 0) + goto err_free_card; snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_cx231xx_pcm_capture); @@ -687,10 +685,9 @@ static int cx231xx_audio_init(struct cx231xx *dev) INIT_WORK(&dev->wq_trigger, audio_trigger); err = snd_card_register(card); - if (err < 0) { - snd_card_free(card); - return err; - } + if (err < 0) + goto err_free_card; + adev->sndcard = card; adev->udev = dev->udev; @@ -709,9 +706,10 @@ static int cx231xx_audio_init(struct cx231xx *dev) "audio EndPoint Addr 0x%x, Alternate settings: %i\n", adev->end_point_addr, adev->num_alt); adev->alt_max_pkt_size = kmalloc(32 * adev->num_alt, GFP_KERNEL); - - if (adev->alt_max_pkt_size == NULL) - return -ENOMEM; + if (!adev->alt_max_pkt_size) { + err = -ENOMEM; + goto err_free_card; + } for (i = 0; i < adev->num_alt; i++) { u16 tmp = @@ -725,6 +723,11 @@ static int cx231xx_audio_init(struct cx231xx *dev) } return 0; + +err_free_card: + snd_card_free(card); + + return err; } static int cx231xx_audio_fini(struct cx231xx *dev)