Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp1150113pxv; Fri, 9 Jul 2021 19:37:07 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxxNI7I+flFp+pNR35JWZhzVhg4wwCsXaLTeGLvyxvVttH6lPxuyx1FJVQ3W7X7r8TspOhm X-Received: by 2002:a05:6402:177c:: with SMTP id da28mr31798904edb.129.1625884626914; Fri, 09 Jul 2021 19:37:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1625884626; cv=none; d=google.com; s=arc-20160816; b=leLZ8vXglG+4I9bOGAYcvSnTzovX/z0DMgs7lOkri+OlHl/UL1HqZFK4QWMABNI/Rh UcbSFDz1qhNuHGfyk/fRg5yiGUSCmGwBBmB6AtjhhdWjHf9w7V8MBiQyX+zMTzAkuhzI HBqXDeQhLXmSxa5civRniIULLqrXUT3BmrCdecz8GhRay7nt4AcA3O4o753c43Ly1gwF K8elAwSpNcQ5EhgXUr8Aszep1FYsZCFVG/kTHYFl1VeENCxwOy5k3u53ToZbpj6UNtGj In4O9tm1pxdZ72MoTm8oikCYhaaXwGG93UMDUaOj+HxdvDfghxZ6sC0dlni+Ahmi4KEd UuGQ== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=cTxurqNk8RwpL4UdgqqWdCNi2R3gCQEV91JbbA4uivk=; b=ZLoIGrIStnvrZzSpfaObXZ0GZDX1rlSE8FFIeNKH4WaOLNQ3vqDsasP4JrLV7tMQps fOByCQ9vP56rsVAVBO4w8STaINPq5fMvJJIqS928uCiWPgvCi3xLO+aDG6X7CqDBp+ew i1dtFsLebMq6+5x6b6zyziuifpTUWXJCJGqS+ZbieCL7rdi2eWtS+CU+xtku3YsFFBQM 3hl5sjDIHrNsqfCqsHV/dngKw/btLmgvqH84wJqlnW1sHAvY91302UaQt0R6k8Gywsl3 IPFnq1iW3EAeK+p8usj5p+HL7QRW4XmBX386liNcyI6PIielW1trKfG7/jAzwu8YftpP mZjQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=fzpEHVw8; 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=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id hv10si8603338ejc.38.2021.07.09.19.36.43; Fri, 09 Jul 2021 19:37:06 -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=@kernel.org header.s=k20201202 header.b=fzpEHVw8; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233156AbhGJCij (ORCPT + 99 others); Fri, 9 Jul 2021 22:38:39 -0400 Received: from mail.kernel.org ([198.145.29.99]:53572 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235732AbhGJCfB (ORCPT ); Fri, 9 Jul 2021 22:35:01 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 5F69D613D4; Sat, 10 Jul 2021 02:32:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1625884337; bh=xZ6YVHXSIOKtRCgjGj41LBEve8g6KiGyPeuZocFI7rs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=fzpEHVw8u/f3bGlRJ06eMlfew4y2DB2dzSoHE64WgvUDjmZEDUCCAl3+lh2lol7sR Y/WdvkzukFHC8Fe/eZMwORhAuUSnYfklJ1RKAEYsvHUwDCZlydPfsu6+zmyE7A8YKT xmzfaIA/PATGnyUePb0GU3COnPv5EMU83SlxkVXHAsfpZK7o0dbXuXYl4r+z2U9/N0 7JkfH3a3G9uh94x04ZXCstSE5h12PpGu71MJbiUIAGI+K0J0PZ/vxTcyRqaXhpmdae toLhQH66yGawAMNYwqMrNkT7ObjAQjcCsD/0SeqzSE0Dnce7Ej7u2JqHemIF6j7kE0 nz1daNTPW0mdQ== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Christophe JAILLET , Greg Kroah-Hartman , Sasha Levin , linux-serial@vger.kernel.org Subject: [PATCH AUTOSEL 4.19 10/39] tty: serial: 8250: serial_cs: Fix a memory leak in error handling path Date: Fri, 9 Jul 2021 22:31:35 -0400 Message-Id: <20210710023204.3171428-10-sashal@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210710023204.3171428-1-sashal@kernel.org> References: <20210710023204.3171428-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Christophe JAILLET [ Upstream commit fad92b11047a748c996ebd6cfb164a63814eeb2e ] In the probe function, if the final 'serial_config()' fails, 'info' is leaking. Add a resource handling path to free this memory. Signed-off-by: Christophe JAILLET Link: https://lore.kernel.org/r/dc25f96b7faebf42e60fe8d02963c941cf4d8124.1621971720.git.christophe.jaillet@wanadoo.fr Signed-off-by: Greg Kroah-Hartman Signed-off-by: Sasha Levin --- drivers/tty/serial/8250/serial_cs.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/drivers/tty/serial/8250/serial_cs.c b/drivers/tty/serial/8250/serial_cs.c index c8186a05a453..271c0388e00d 100644 --- a/drivers/tty/serial/8250/serial_cs.c +++ b/drivers/tty/serial/8250/serial_cs.c @@ -306,6 +306,7 @@ static int serial_resume(struct pcmcia_device *link) static int serial_probe(struct pcmcia_device *link) { struct serial_info *info; + int ret; dev_dbg(&link->dev, "serial_attach()\n"); @@ -320,7 +321,15 @@ static int serial_probe(struct pcmcia_device *link) if (do_sound) link->config_flags |= CONF_ENABLE_SPKR; - return serial_config(link); + ret = serial_config(link); + if (ret) + goto free_info; + + return 0; + +free_info: + kfree(info); + return ret; } static void serial_detach(struct pcmcia_device *link) -- 2.30.2