Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp1144551pxv; Fri, 9 Jul 2021 19:25:23 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyjzXPdpk6Xnr9njHQmL90QzoRl4DDfDYW+FrKoKSkSMjbGGVmAZmx2c+HzwO6XjzI/uLfS X-Received: by 2002:a17:906:7a56:: with SMTP id i22mr1567021ejo.94.1625883923039; Fri, 09 Jul 2021 19:25:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1625883923; cv=none; d=google.com; s=arc-20160816; b=jhf9u42e9p/Ek4n9eJdT8YMZne8JCY8mJNNQR7NMZ51Cm9PVCN70XjZEYhMjxWl3Lt k6vr0PWtusBDaNb13VkbxV/vF5R+pjP+3ww9qzJp6h60n3EsRXiXCeiw+NNQr1BF6MT9 Wg8m6fKc8S4tefdulBauWIDr0dBk3rFMXAUnwdGNdn2/wXZitdqj2mRvDx4D4X2Mjf5q n4Xmi+62/VTGjDwZ7nPz+ZgV5X8f1O3IQTc7lbBJcMDg9BVkKUEs2e8wrC8+1lijy9Jr QAKDzilIoOcyFVe9UrsfwHuKT+aAJW4L57wFG/GuSeDG33am1PJLkMOEfsMUsRbLKEaU iNVw== 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=Czzs1BHprqs51en8f/YmgTjNDqIAr9yrZP4eLelHCrA=; b=SPxTJz9pnTfoPi/ENE66l311DG+LgPTGI3mwGM9AtJPt0xnJ2ioG8VtDwPIxEepla8 6xSg9jbwfpF5XgGtYhaGfmaSHuQX3c6UtiEf75Ohe3hAlWidBBAGKdHEuU/zsAMEe4p7 f3x5BqIEZH+mnAAIIrudm+8+ieiPtMLjAd07lutA28DMy65goEnFPWBgPJe0qHuR00bV sljUtMhCvvkTWNrjorzgDiKDnonyfmE7Fj7hVdxP6H/QZgfJhefButhUd/3cPFN1lpSe gT/QvmgBFOn9H8HchdSpFiWY5owfohRyg5PkIIM9qmhX7obHDxnX1met8kEUYiSimqdq vK8g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=AP0WJhtm; 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 e9si9052533edv.146.2021.07.09.19.24.59; Fri, 09 Jul 2021 19:25: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=AP0WJhtm; 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 S233423AbhGJC0C (ORCPT + 99 others); Fri, 9 Jul 2021 22:26:02 -0400 Received: from mail.kernel.org ([198.145.29.99]:42146 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231908AbhGJCZU (ORCPT ); Fri, 9 Jul 2021 22:25:20 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id E5226613CC; Sat, 10 Jul 2021 02:22:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1625883756; bh=jpeVSUEUTVSAs5B0cP6g1fCG9vedipyGLpx+i1vy83Y=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=AP0WJhtmoOKToaPwOk5t6MRYBDRLDBZxU8sCVpNccqiMTAFDR+agVjUVrsxfOH/AL 7QTxGSdYJn8UkgayHcJwgm6tRwWg5KExjqlOku2+Qpw1u1tzoIthFlxMe+NDqIcUlO TvLR5KwuBrxOruSuCMYN3+J3j+ZuMsKXZ73V4cSqmxvIzlr4ofzgcZKHXvFVGhxTTM /mH7vUoMxB1SKiN6G+ZaAECM1hPreXhZvGuDjpOVM8oJ0IpugM2K38f5qYS9W4EPlc y8Aez4QPSc6wX34q9zxWLGy5O7XohRMezq5KN3KfognudAZbYWG1IEn840ooI+EMCs +tV34nzeYL9+Q== 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.12 031/104] tty: serial: 8250: serial_cs: Fix a memory leak in error handling path Date: Fri, 9 Jul 2021 22:20:43 -0400 Message-Id: <20210710022156.3168825-31-sashal@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210710022156.3168825-1-sashal@kernel.org> References: <20210710022156.3168825-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 35ff6627c61b..2cd2acc09cc4 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