Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp4852923pxj; Wed, 9 Jun 2021 03:35:04 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz4c/B+PcPxiV1xD2VgUHHcj1DjXdaEHloYt5doJfX+TBpVkz6RhD9PNChOPdYFKOBcS8Xw X-Received: by 2002:a17:906:55cb:: with SMTP id z11mr27954482ejp.475.1623234904332; Wed, 09 Jun 2021 03:35:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623234904; cv=none; d=google.com; s=arc-20160816; b=0biRr9H/d6cxlyhhLntgh7YaCVhM7o2iuxBRUY+7ZzmyMPtOAPvncfgfsHMlc6x7rZ d+NHMLkharV0VtFaq+M4HJpbHFTtkpj8QNgHNfPzBdrLysgeUBTHTZl4XO0+YbKdbSgk mtezLonYYg+1ty7c3UtFrMwnjKIFAlr4H3lfJt8VJiUMcomiicpzdShm07ix4a93vTei rgamCpmEOPQmrI8CbT5eIybE/61kTz8HlFHaTLRBU4ETmPAjRIcYXsgf15+tSa5t3jie zf9B8oSX0550TYqGMfY3l2PW2ILvEZvzDE7PefZauO7ZlsLHes6HbceK13QJLl1a7B3S mQRw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=jt66i0yHZymi3DFfW8enRSrQ/qfuBPRMwbx9Y4kxO8o=; b=gtdwHcd8D9oOLGFu8mr7FO/ijriTWUqo79dQs85jdEbYPu12IBC+hFMQZT+3vSAVkf KOaveCBvBLWhwXzXxB2Tu69GsuThnu6dpZxipu47z0qzZnEADDxs/E7U8C5hFvkoLHX1 ajZhP8eZvzABCTMwZL5BDZ66jyqu2SgAQ+llUNJWew/tjuhcUQXxs+XNpkwzUhNmLiQ7 r7BLedexKkFTBi7/zOQDnaEXjS5z+K+HiXINy9iQwJT7ZWpR1hnxTKbtzPB248s3Hrzb k1QYxqHdJSDOpWSNtQfbsGbU//OHNWDoa16J1QZ70c+qH9Z56dbYG1aAuNFb8ZHnU0qs 7Lng== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=C7js6YI+; 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=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id ck2si2041962edb.395.2021.06.09.03.34.40; Wed, 09 Jun 2021 03:35:04 -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=@linuxfoundation.org header.s=korg header.b=C7js6YI+; 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=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236968AbhFHTHf (ORCPT + 99 others); Tue, 8 Jun 2021 15:07:35 -0400 Received: from mail.kernel.org ([198.145.29.99]:35576 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236562AbhFHS60 (ORCPT ); Tue, 8 Jun 2021 14:58:26 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 727EA61626; Tue, 8 Jun 2021 18:42:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1623177765; bh=Yl7IPL85YzCd2CUddMcgindgnXZi0j50a/KS615JKeo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=C7js6YI+7IIJpXZ+ruUP0dof1v+9gwOpPkefGnKMaogPA6UyZ6lp1amtZWKCRkX3a 4zj5tFzZHJlcvarnIKnub3GuHxKtCVznCsTLmK1BawvlFyvss/AtksoRlYjWkep76E TAtRg0Mg9TK0q3lCjD6h2g5ibRMMBn/DjIV9UEtA= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Pavel Skripkin , "David S. Miller" Subject: [PATCH 5.10 092/137] net: caif: fix memory leak in cfusbl_device_notify Date: Tue, 8 Jun 2021 20:27:12 +0200 Message-Id: <20210608175945.490812280@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210608175942.377073879@linuxfoundation.org> References: <20210608175942.377073879@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Pavel Skripkin commit 7f5d86669fa4d485523ddb1d212e0a2d90bd62bb upstream. In case of caif_enroll_dev() fail, allocated link_support won't be assigned to the corresponding structure. So simply free allocated pointer in case of error. Fixes: 7ad65bf68d70 ("caif: Add support for CAIF over CDC NCM USB interface") Cc: stable@vger.kernel.org Signed-off-by: Pavel Skripkin Signed-off-by: David S. Miller Signed-off-by: Greg Kroah-Hartman --- net/caif/caif_usb.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) --- a/net/caif/caif_usb.c +++ b/net/caif/caif_usb.c @@ -115,6 +115,11 @@ static struct cflayer *cfusbl_create(int return (struct cflayer *) this; } +static void cfusbl_release(struct cflayer *layer) +{ + kfree(layer); +} + static struct packet_type caif_usb_type __read_mostly = { .type = cpu_to_be16(ETH_P_802_EX1), }; @@ -127,6 +132,7 @@ static int cfusbl_device_notify(struct n struct cflayer *layer, *link_support; struct usbnet *usbnet; struct usb_device *usbdev; + int res; /* Check whether we have a NCM device, and find its VID/PID. */ if (!(dev->dev.parent && dev->dev.parent->driver && @@ -169,8 +175,11 @@ static int cfusbl_device_notify(struct n if (dev->num_tx_queues > 1) pr_warn("USB device uses more than one tx queue\n"); - caif_enroll_dev(dev, &common, link_support, CFUSB_MAX_HEADLEN, + res = caif_enroll_dev(dev, &common, link_support, CFUSB_MAX_HEADLEN, &layer, &caif_usb_type.func); + if (res) + goto err; + if (!pack_added) dev_add_pack(&caif_usb_type); pack_added = true; @@ -178,6 +187,9 @@ static int cfusbl_device_notify(struct n strlcpy(layer->name, dev->name, sizeof(layer->name)); return 0; +err: + cfusbl_release(link_support); + return res; } static struct notifier_block caif_device_notifier = {