From patchwork Fri Jan 23 17:13:09 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Takashi Iwai X-Patchwork-Id: 5696991 Return-Path: X-Original-To: patchwork-alsa-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 3807AC058D for ; Fri, 23 Jan 2015 17:25:56 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 6A52F201EC for ; Fri, 23 Jan 2015 17:25:55 +0000 (UTC) Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) by mail.kernel.org (Postfix) with ESMTP id D363B20259 for ; Fri, 23 Jan 2015 17:25:52 +0000 (UTC) Received: by alsa0.perex.cz (Postfix, from userid 1000) id 614C1265800; Fri, 23 Jan 2015 18:20:47 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 Received: from alsa0.perex.cz (localhost [IPv6:::1]) by alsa0.perex.cz (Postfix) with ESMTP id 23A762657ED; Fri, 23 Jan 2015 18:17:49 +0100 (CET) X-Original-To: alsa-devel@alsa-project.org Delivered-To: alsa-devel@alsa-project.org Received: by alsa0.perex.cz (Postfix, from userid 1000) id 2596E2654CC; Fri, 23 Jan 2015 18:14:02 +0100 (CET) Received: from mx2.suse.de (cantor2.suse.de [195.135.220.15]) by alsa0.perex.cz (Postfix) with ESMTP id 92B042654EB for ; Fri, 23 Jan 2015 18:13:41 +0100 (CET) Received: from relay1.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id E165FAD8B; Fri, 23 Jan 2015 17:13:38 +0000 (UTC) From: Takashi Iwai To: alsa-devel@alsa-project.org Date: Fri, 23 Jan 2015 18:13:09 +0100 Message-Id: <1422033203-23254-3-git-send-email-tiwai@suse.de> X-Mailer: git-send-email 2.2.2 In-Reply-To: <1422033203-23254-1-git-send-email-tiwai@suse.de> References: <1422033203-23254-1-git-send-email-tiwai@suse.de> Cc: Stefan Hajnoczi , Chris Rorvick Subject: [alsa-devel] [PATCH 02/16] ALSA: line6: Fix memory leak at probe error path X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: alsa-devel-bounces@alsa-project.org Sender: alsa-devel-bounces@alsa-project.org X-Virus-Scanned: ClamAV using ClamSMTP Fix memory leak at probe error path by rearranging the call order in line6_destruct() so that the common destructor is always called. Also this simplifies the error path to a single goto label. Signed-off-by: Takashi Iwai --- sound/usb/line6/driver.c | 53 ++++++++++++++++++++++++------------------------ 1 file changed, 27 insertions(+), 26 deletions(-) diff --git a/sound/usb/line6/driver.c b/sound/usb/line6/driver.c index b783c0788e45..2eed6fbd99c4 100644 --- a/sound/usb/line6/driver.c +++ b/sound/usb/line6/driver.c @@ -507,10 +507,32 @@ int line6_probe(struct usb_interface *interface, int interface_number; int ret; + ret = snd_card_new(line6->ifcdev, + SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1, + THIS_MODULE, 0, &card); + if (ret < 0) { + kfree(line6); + return ret; + } + + line6->card = card; + strcpy(card->id, line6->properties->id); + strcpy(card->driver, DRIVER_NAME); + strcpy(card->shortname, line6->properties->name); + sprintf(card->longname, "Line 6 %s at USB %s", line6->properties->name, + dev_name(line6->ifcdev)); + card->private_data = line6; + card->private_free = line6_destruct; + + usb_set_intfdata(interface, line6); + + /* increment reference counters: */ + usb_get_dev(usbdev); + /* we don't handle multiple configurations */ if (usbdev->descriptor.bNumConfigurations != 1) { ret = -ENODEV; - goto err_put; + goto error; } /* initialize device info: */ @@ -523,7 +545,7 @@ int line6_probe(struct usb_interface *interface, properties->altsetting); if (ret < 0) { dev_err(&interface->dev, "set_interface failed\n"); - goto err_put; + goto error; } /* store basic data: */ @@ -533,36 +555,16 @@ int line6_probe(struct usb_interface *interface, line6_get_interval(line6); - ret = snd_card_new(line6->ifcdev, - SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1, - THIS_MODULE, 0, &card); - if (ret < 0) - goto err_put; - - line6->card = card; - strcpy(card->id, line6->properties->id); - strcpy(card->driver, DRIVER_NAME); - strcpy(card->shortname, line6->properties->name); - sprintf(card->longname, "Line 6 %s at USB %s", line6->properties->name, - dev_name(line6->ifcdev)); - card->private_data = line6; - card->private_free = line6_destruct; - - usb_set_intfdata(interface, line6); - - /* increment reference counters: */ - usb_get_dev(usbdev); - if (properties->capabilities & LINE6_CAP_CONTROL) { ret = line6_init_cap_control(line6); if (ret < 0) - goto err_destruct; + goto error; } /* initialize device data based on device: */ ret = private_init(interface, line6); if (ret < 0) - goto err_destruct; + goto error; /* creation of additional special files should go here */ @@ -571,11 +573,10 @@ int line6_probe(struct usb_interface *interface, return 0; - err_destruct: + error: if (line6->disconnect) line6->disconnect(interface); snd_card_free(card); - err_put: return ret; } EXPORT_SYMBOL_GPL(line6_probe);