Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp4734789pxj; Wed, 9 Jun 2021 00:04:25 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwSKstdB0BFPTSpTSMBfulLC10936tarR656wcpqVwLxy1QqTDJ/GQXZ/8NqEORRqNV2Fk1 X-Received: by 2002:a17:906:c1d2:: with SMTP id bw18mr26974682ejb.123.1623222265114; Wed, 09 Jun 2021 00:04:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623222265; cv=none; d=google.com; s=arc-20160816; b=tKHi4eeE2xBym59qiq48c0nOZOL1PWE2EXIPFlxVnG0/ONAqrOHfvlpdvbNBCpDIVT 6PU2KBL99WKR3WGECZSGtFsqh4SzwCIrJjdCnS2J1kiU+CnjNO73SKP6cpWXoWq2f70E JrY6dUvh5asRrmWnkZALmJrJtxF5Ig76B1u/ngQnx9iKPtV5ky1GhYsdB2+LQN0ChFoM DOUJ86NCkrwQgYDoQJ7DwKI+hTQX8HKPv+12U5wUIY/VrGqbi77cO1shQTLBkA7+yLIY oIZslHQJxsiuxI88xsZeRs5H1htsNhn3mXMAsPTrHvqj67HsCMq/uGVUYXId5Xfvpf5c zLzQ== 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=P+Mb4dKFdL9pG2erbijvFOY8jQpRvY8YB8TvqiXNVeM=; b=q/I1RqOpuI7U87kGBadBT6NUvPPjYI8u1C2twRFLPXZreQ18ptu0v+zlJlM/nDQxbZ MY/hE3IU8W3McZXjLsjtELvOsBC1LeNdllf5cMvglVxZZ+PAepKRisZ2J+t4fC7stHjA PezrSv5yCJngkqJFrDCBYe/K0jyf6CYMT3jwAVYoiZ8427mNqYLUJxZR9Y4aPFJ2yVT+ LlEcFuKpdXmeScMLr5yT+RoT0S0k6xa2bSyMd1CMoQJIoOKOjwYkTHIHxIWcg8Y1ucfK qenysKYWWAsPKl1c81ksbNfAE7hLD81fhTlX59P39ofJ/RTcJi+qpL/BxGA+tx6XXfQq oEZg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=K82kFTy1; 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 y4si2064024edi.355.2021.06.09.00.04.02; Wed, 09 Jun 2021 00:04:25 -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=K82kFTy1; 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 S234702AbhFHSiI (ORCPT + 99 others); Tue, 8 Jun 2021 14:38:08 -0400 Received: from mail.kernel.org ([198.145.29.99]:56100 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234886AbhFHSf7 (ORCPT ); Tue, 8 Jun 2021 14:35:59 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 5375C613CE; Tue, 8 Jun 2021 18:32:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1623177149; bh=u/YoHiPNvaOjM6DSUbtCv9cuDvMIjhzS/H0FsmXQYhk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=K82kFTy1a0dpPI5jik+gnDb6zVQ0CR8lkC6RQTgVans+YVmpItRc/mogGBQYviLxu 2qKMiTDZw9LqE0oVzT/JezZxlLMtz/pDYfY7JAYlrg3Dyqq03scvy6jzJpBnLFXtMs J0vSk2Hlh9xbP7dy172foAo3aEnHn0TuLSAayw4U= 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 4.14 18/47] net: caif: fix memory leak in cfusbl_device_notify Date: Tue, 8 Jun 2021 20:27:01 +0200 Message-Id: <20210608175931.076573908@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210608175930.477274100@linuxfoundation.org> References: <20210608175930.477274100@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 @@ -116,6 +116,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), }; @@ -128,6 +133,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 && @@ -170,8 +176,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; @@ -181,6 +190,9 @@ static int cfusbl_device_notify(struct n layer->name[sizeof(layer->name) - 1] = 0; return 0; +err: + cfusbl_release(link_support); + return res; } static struct notifier_block caif_device_notifier = {