Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp1148542pxv; Fri, 9 Jul 2021 19:33:46 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz0NNm66lqWuYWAvGm/glsPQC4yhVA7etvgN03wJodVPLd4H/LU3ubvDIYyrrSrEqCUCmWN X-Received: by 2002:a17:906:6d97:: with SMTP id h23mr40368585ejt.467.1625884426330; Fri, 09 Jul 2021 19:33:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1625884426; cv=none; d=google.com; s=arc-20160816; b=di7DKknHSbUVHZo6marReaIo++dFSOj59PbPr0D4sQ7RT1uvqY4fgjDGi/NnVPyy/9 PWHhi5DfRRNZHBFbOcP+zbNFAHpjGTqPkjm/8YDs8NJDIP1dry0GfEyPNthJ1LkDnRBo p3Q0PPqZhvfjXhQWJW43o+8mBgaggRUkbNr090Hv9aedWyBp/72c1LjMrv2/eB2S047I lrF3ymmFF/zmYH0L9pQp7h7goJoNW/tSvWKkgQsTy9u6ylMjO/zYsFBMt8SYZwewNvJv Evdfy7eFaoMczfe6PIvLJTYthAfMwW9GR+hvBK3hPu+80Dpbu5altB6EBWKsAtT9cOmN hsmQ== 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=h5FwUV+uP1FksX6JQgHPqZFIOvqyho5JKHmLGGldqns=; b=h+OUVwmPIuRbqUYLNIbjn85J4FObgmJsjUL9DPI/znrBGeTRDjsUuzF3IAqDuDNAd+ DGSsLbSxj7eXvxDYUvXzHafjt3BUc0dyPofOdNvRTc8JECHyp3SZPVd4rouqX+bXB9Sq UBm6n9dKwVAngPHnXvf70R6PPqzlaQTEQogNwx11pzHaoFhkPT0xWauMnfb8xGSpfohW 1pHO1tkIpQ0pcn45rUzxXzsgk4Ap0FDbRVAkboajia5F1UYcxnl9rSS0mwMoW/dzdbdr n5j6rveNLLydopGj48SSzJJgN9b7JobirmS3HZhTagoidC12y/4vKwTYVduoiWJDY1Ig hkIQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=IiaZqn6f; 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 m25si9025621ejb.570.2021.07.09.19.33.22; Fri, 09 Jul 2021 19:33:46 -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=IiaZqn6f; 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 S235196AbhGJCei (ORCPT + 99 others); Fri, 9 Jul 2021 22:34:38 -0400 Received: from mail.kernel.org ([198.145.29.99]:42542 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234010AbhGJC2M (ORCPT ); Fri, 9 Jul 2021 22:28:12 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 4B99661448; Sat, 10 Jul 2021 02:25:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1625883907; bh=wHxVcjjAZcqC94MO5ze/Inx+2gIkGy+ugnixmUAKBmE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=IiaZqn6fJjPXltT8srZ37uXPh4M+VaqpDQLPStdreSIa5RJ2grajRGbOPislMHJcs tPglnUvbkLrF5L/Wq+RWALZhB7uRvMgauWPrZn7HaNEzqB2MhM3ekGy7yb79wIXwOY 02iMaXJXnQe8VC6E3UDJGjMJXdrVv6os72cf2d6lOMsgrTot9M9JkAQeNhOnVQN7Ry 46rmP4G1PcmdL+Z/wq7M9Tr5vyljHriF+8PcaqfWqbq6uvKRJ5by3Gjof9CUsLsGGA FLsez0e3VIi3SR+DdR8XNFXphmYLP7WpbucSZgBIpgqYah3CSaIpxTfWgHU1QJ8ja2 M8HgSdBGF8gjQ== 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.10 29/93] tty: serial: 8250: serial_cs: Fix a memory leak in error handling path Date: Fri, 9 Jul 2021 22:23:23 -0400 Message-Id: <20210710022428.3169839-29-sashal@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210710022428.3169839-1-sashal@kernel.org> References: <20210710022428.3169839-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 e3d10794dbba..612473a2dfe9 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