Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3469956imu; Sun, 11 Nov 2018 15:50:27 -0800 (PST) X-Google-Smtp-Source: AJdET5dX0nN9RFl70HTnJmqMLNhUfs1YSLfU6m32frHM2edALRRsRvmOP5CHxMkaZMqjGXTRg83n X-Received: by 2002:a17:902:4083:: with SMTP id c3-v6mr17949752pld.181.1541980227264; Sun, 11 Nov 2018 15:50:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541980227; cv=none; d=google.com; s=arc-20160816; b=gRqQ189CfAVVu0yOeeO8R1ZkQM3MXBMpihro02jDGc1RunCI4GXOO0j2L3qIPgkZ5F 9XLZ40zmFZgpf8lE7YcYctUZYvTIytEae7t9jpEn5CTwd3P+gCDQb8R+MUnvuNKpdkJd 8nA5k8YrxSjtCUEF293VqcRzRxm8srmen56rwfpP91B1JmxynqkUvoYHDqcLnjxDkLDq nvXkx2Owm0pFeDSpN+6pOPdZmlVuiZkvtI0SmxzsJVUThNMeQ0ArXOGNqKAlQXrIMmkI ZGD04FP47qbbr3sw2rR7H6goh/02gYAx+kx0o/kWBnfsVoOP0urMdyLaGlDD/au38OE9 iqFA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=c4uIrnsScxMEnDCUT8cf1UPitff4YAdB3zZg/3Pyeng=; b=Ka41hUmlVK3Zw6LNwoo9UvQKGqhOYxAAVyo/4OaJbbD3cTcyd4+sWhw1njDzqOMfDt XaxW31JeiFicuyrhPskxSOwP5gq0Ld0J3jt0CJ0br6tcZEXTfoKr0VRJaQFkQthCnl3d 8tTR4NkCaui35rt7nWcBMC9NV1dTZnu64YPwmKs0nkj6aKtba/VpDC6ghEUuhW+dr61E 5FioqA+f35GSXpd9fVCy6hAInwg1sr3O2HirwIqmIeM4XtlqQZyOyXiCyhF7gjVoPnl1 ohy8zTS23TJ8Dk3NzwQ+PoYJoY+Ts+CUJwgsHnG9tQauOTfmwUIcUuaqkgGIACE2PQ4u hZTA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=U3UlU2up; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x3-v6si17075113pfb.122.2018.11.11.15.50.12; Sun, 11 Nov 2018 15:50:27 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=U3UlU2up; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732989AbeKLISh (ORCPT + 99 others); Mon, 12 Nov 2018 03:18:37 -0500 Received: from mail.kernel.org ([198.145.29.99]:38154 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732963AbeKLISh (ORCPT ); Mon, 12 Nov 2018 03:18:37 -0500 Received: from localhost (unknown [206.108.79.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id DFE1A21780; Sun, 11 Nov 2018 22:28:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1541975320; bh=AGkhQk2r6oZOUbLqcJLZ7vPaBtSm6OHbs5Z0yl37v2s=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=U3UlU2upjUB71psnbJkXYzpW4wbIh4MaQX+KD2A5bugPdPQ+1/yRl37OeGzJ0fQaz FjLLTUS/SnPkVpUV33e3SwszkfS8Uj74ZcZ2cnzldmzfsZqP9tn5rkJZNidyfurHZS 4G+NRqPyH5hL+EBEGH5UZTouqOj0TbYGywE0w0YE= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Colin Ian King , Bjorn Andersson Subject: [PATCH 4.19 317/361] rpmsg: smd: fix memory leak on channel create Date: Sun, 11 Nov 2018 14:21:04 -0800 Message-Id: <20181111221658.805217784@linuxfoundation.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181111221619.915519183@linuxfoundation.org> References: <20181111221619.915519183@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.19-stable review patch. If anyone has any objections, please let me know. ------------------ From: Colin Ian King commit 940c620d6af8fca7d115de40f19870fba415efac upstream. Currently a failed allocation of channel->name leads to an immediate return without freeing channel. Fix this by setting ret to -ENOMEM and jumping to an exit path that kfree's channel. Detected by CoverityScan, CID#1473692 ("Resource Leak") Fixes: 53e2822e56c7 ("rpmsg: Introduce Qualcomm SMD backend") Cc: stable@vger.kernel.org Signed-off-by: Colin Ian King Signed-off-by: Bjorn Andersson Signed-off-by: Greg Kroah-Hartman --- drivers/rpmsg/qcom_smd.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) --- a/drivers/rpmsg/qcom_smd.c +++ b/drivers/rpmsg/qcom_smd.c @@ -1122,8 +1122,10 @@ static struct qcom_smd_channel *qcom_smd channel->edge = edge; channel->name = kstrdup(name, GFP_KERNEL); - if (!channel->name) - return ERR_PTR(-ENOMEM); + if (!channel->name) { + ret = -ENOMEM; + goto free_channel; + } spin_lock_init(&channel->tx_lock); spin_lock_init(&channel->recv_lock); @@ -1173,6 +1175,7 @@ static struct qcom_smd_channel *qcom_smd free_name_and_channel: kfree(channel->name); +free_channel: kfree(channel); return ERR_PTR(ret);