From patchwork Sat Jun 10 15:59:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marion & Christophe JAILLET X-Patchwork-Id: 691612 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4C71BC7EE29 for ; Sat, 10 Jun 2023 15:59:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235728AbjFJP7s (ORCPT ); Sat, 10 Jun 2023 11:59:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59516 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235704AbjFJP7o (ORCPT ); Sat, 10 Jun 2023 11:59:44 -0400 Received: from smtp.smtpout.orange.fr (smtp-13.smtpout.orange.fr [80.12.242.13]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0C82B30D0 for ; Sat, 10 Jun 2023 08:59:42 -0700 (PDT) Received: from pop-os.home ([86.243.2.178]) by smtp.orange.fr with ESMTPA id 80zwqFULNV4eY8109qBQ5s; Sat, 10 Jun 2023 17:59:41 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=wanadoo.fr; s=t20230301; t=1686412781; bh=rgPp2pCaELfgMWRAU3EmU6s0PWnLrCfx5I54gIqT2d4=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=cDOdpzBoF3bvokNC1MgJ44SiukpgXDu7b2i971OIkrmPMgiv4q3MS+0OIPNqkYG2W DbZDdZbQ8PPHSnqi6TgpnMDf0ALKVQ7De3YcCGtxKgB/Fb/saX4ij4Mm+dWthe2YeM 27EBBuf7tQz1DVgsWoC3wVfhlW+zcWn7KVjUkADyUA7XaDAerMaaYO1Jp4485iilQx Lpihc1DhbjzDcjJMwCduwy3HPVX3IJXdYQu+tI1fEhQOP2sRQ3JRxeOzfZ2oJAzyDQ fEUK9t6UMRt9bLiSwnUKpbNZczmJa4eehmY/H8PyNxjSZEifXdP3qi+IpwmGKVmRNb skhA+uAMYoiMQ== X-ME-Helo: pop-os.home X-ME-Auth: Y2hyaXN0b3BoZS5qYWlsbGV0QHdhbmFkb28uZnI= X-ME-Date: Sat, 10 Jun 2023 17:59:41 +0200 X-ME-IP: 86.243.2.178 From: Christophe JAILLET To: Krzysztof Kozlowski , Alim Akhtar , Greg Kroah-Hartman , Jiri Slaby , Kukjin Kim , Thomas Abraham Cc: linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org, Christophe JAILLET , stable@vger.kernel.org, Andi Shyti , linux-arm-kernel@lists.infradead.org, linux-samsung-soc@vger.kernel.org, linux-serial@vger.kernel.org Subject: [PATCH v2 2/3] tty: serial: samsung_tty: Fix a memory leak in s3c24xx_serial_getclk() when iterating clk Date: Sat, 10 Jun 2023 17:59:26 +0200 Message-Id: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-serial@vger.kernel.org When the best clk is searched, we iterate over all possible clk. If we find a better match, the previous one, if any, needs to be freed. If a better match has already been found, we still need to free the new one, otherwise it leaks. Cc: # v3.3+ Reviewed-by: Krzysztof Kozlowski Reviewed-by: Andi Shyti Fixes: 5f5a7a5578c5 ("serial: samsung: switch to clkdev based clock lookup") Signed-off-by: Christophe JAILLET Reviewed-by: Jiri Slaby --- I think that some clk_put() are also missing somewhere else in the driver but won't be able to investigate further. v2: No code change Add Cc: stable [Andi Shyti, as suggested for patch 1/2] Add R-b tags v1: https://lore.kernel.org/all/93bf8f574310256fcea50e5c5a62b5c37e20bb14.1686285892.git.christophe.jaillet@wanadoo.fr/ --- drivers/tty/serial/samsung_tty.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/drivers/tty/serial/samsung_tty.c b/drivers/tty/serial/samsung_tty.c index a92a23e1964e..0b37019820b4 100644 --- a/drivers/tty/serial/samsung_tty.c +++ b/drivers/tty/serial/samsung_tty.c @@ -1490,10 +1490,18 @@ static unsigned int s3c24xx_serial_getclk(struct s3c24xx_uart_port *ourport, calc_deviation = -calc_deviation; if (calc_deviation < deviation) { + /* + * If we find a better clk, release the previous one, if + * any. + */ + if (!IS_ERR(*best_clk)) + clk_put(*best_clk); *best_clk = clk; best_quot = quot; *clk_num = cnt; deviation = calc_deviation; + } else { + clk_put(clk); } }