Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp1143653pxv; Fri, 9 Jul 2021 19:23:23 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw+hebTbcFI6kkJzaVBJjbvlUijwgjXi4xiwiyokA8deRoJfeCBMyoFyqZHcbrhomA3I/di X-Received: by 2002:a17:906:fad5:: with SMTP id lu21mr41422134ejb.469.1625883803316; Fri, 09 Jul 2021 19:23:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1625883803; cv=none; d=google.com; s=arc-20160816; b=TmL3eLhuLJfciLcz91teKzBUn8JzPy3zsQKA3NcGSG40KpBk6Gp0Tt3YHej1OAUve3 fQNFuPKyssZsnyWUGxUjKJqWXurOwgbDdjMJYC2DPLwqz5XlQwh6PzV+Lj7JbfVxpdav GT4t7TOuBgTpqlXws1RiiRQ49kPw8n//Kip/UQLRGWCQRz8iZjXVr4msULSvCjTaSHIh JEh26EpnWVF8uksknB6LQPoHvRxHow3d+JcmwZ+naq9muCE3H+3rLERm16YjYlclkpLD edmMA7xzTAOPjMJl617cNHZo2jGtaQ2f8B2dg0I1MoVFizMijVt2vCbYkFIF8wXBGLS7 kV0g== 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=lG+rIOfuNYxgyP8HBUvtwW2n7P6+audVu8j2eq1ws50=; b=Q1HtEJvKJp3C1e6qgIYSI79CFdRYYgG+1aM4mnjk05DB9HaRmHT+o2t6AYOcKfU1lv ggAVVTqqVkbMm9aXPntjtja3cBdBxrS1hM+3urYIsxi3Ij0Aj+3qCn8Jyud71q56PogU oBgZfevgAr4qbFzudUo82xMRjoFDXsIoZoK4aZLb2vAjMEWQCCPO1N8S5PYW/IRB5S8n aS3yPed/dgRwpRzVR4AYkMJUIyHKF3c+GNDJZys1u34oXzJGOJ6nZJrVoIr2UETzvNBf Run5PQIbcde6CosY+feFj3YOSjTddfZwTl0uc6cCzZG4L0r56eL70aUDunz/h4c4qB3j D/Rw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=m2MwLsyT; 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 nc38si10837432ejc.708.2021.07.09.19.22.59; Fri, 09 Jul 2021 19:23:23 -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=m2MwLsyT; 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 S232676AbhGJCV5 (ORCPT + 99 others); Fri, 9 Jul 2021 22:21:57 -0400 Received: from mail.kernel.org ([198.145.29.99]:37724 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232412AbhGJCVV (ORCPT ); Fri, 9 Jul 2021 22:21:21 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 65B1E613C9; Sat, 10 Jul 2021 02:18:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1625883517; bh=Q+VIecXUnKLfkoaor4FWcE0TuJUPodlMlYeh7ZaMgKU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=m2MwLsyTltOuaSIeBlwzoo/ztCmbiODwBlErA+ACsWa0fUCQmuONAfxH/7jikrbxQ yfzPrWRbkBl5+Fk00CMH53V1tzr+5FHbP0VJfWrqn1uMCbRrWjZ9pZb5DZg5x6IVPI JDFsYs7SHzX/sWGtIdJjyBi+cLlJZ/Yze4W4nusG47hTlvUrQJTskWysXwV5Gu2SvT HevIBzyKQaHa4CBDJ+++vYwswqc9P4SalF8zwD111f4och0cET5mPmu5/MRRQk55Xo DV3nWDGQe7/yfQEIJyEQakPs+02/xjpfKcBwCVqTaHQ6HM6TkR5O0QI56rVIW0B46w wnnWFsy94DfKA== 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 5.13 035/114] tty: serial: 8250: serial_cs: Fix a memory leak in error handling path Date: Fri, 9 Jul 2021 22:16:29 -0400 Message-Id: <20210710021748.3167666-35-sashal@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210710021748.3167666-1-sashal@kernel.org> References: <20210710021748.3167666-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 63ea9c4da3d5..3708114343b0 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