From patchwork Sat Apr 1 20:03:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg Kroah-Hartman X-Patchwork-Id: 13197207 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 3ADB0C6FD1D for ; Sat, 1 Apr 2023 20:03:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229529AbjDAUDi (ORCPT ); Sat, 1 Apr 2023 16:03:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34798 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229450AbjDAUDh (ORCPT ); Sat, 1 Apr 2023 16:03:37 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D864AB761; Sat, 1 Apr 2023 13:03:35 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 99C34B801BE; Sat, 1 Apr 2023 20:03:34 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E9301C433D2; Sat, 1 Apr 2023 20:03:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1680379413; bh=/Fygv1Pu1n1/p5GSibbFK63D+X3dR2C/FWH95CEqEGk=; h=From:To:Cc:Subject:Date:From; b=zUFq15iAC6ea58bjO5m2qy/Sv5UBX72zObbg4TVIcVZtUI+WapR6+rYY4XQNi+ALR CBfsHTjAIr9PLl1Ged4hNRgJPVN1A/oWdba63NMFZqIL+SgJCTeZI/xrVbETkXrhc9 mfwuxLAHL9VmiDzNdpq+CbIQ6sZ+CpMprbceXaV4= From: Greg Kroah-Hartman To: linux-mmc@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Greg Kroah-Hartman , Maxim Levitsky , Alex Dubov , Ulf Hansson , "Rafael J. Wysocki" , Hans de Goede , Kay Sievers , stable , Mirsad Goran Todorovac Subject: [RESEND PATCH] memstick: fix memory leak if card device is never registered Date: Sat, 1 Apr 2023 22:03:27 +0200 Message-Id: <20230401200327.16800-1-gregkh@linuxfoundation.org> X-Mailer: git-send-email 2.40.0 MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=2048; i=gregkh@linuxfoundation.org; h=from:subject; bh=/Fygv1Pu1n1/p5GSibbFK63D+X3dR2C/FWH95CEqEGk=; b=owGbwMvMwCRo6H6F97bub03G02pJDCkafbynebelm4efe19op9yiYBfdNHm3o+EhURXWBEOXnkMb QvZ1xLIwCDIxyIopsnzZxnN0f8UhRS9D29Mwc1iZQIYwcHEKwERSNBgWrPv475Tkh9ZEnfD7vXvUv0 +s8jl3lWF+9ocTKy5nznTIOjHbcOHaq+KuljmvAA== X-Developer-Key: i=gregkh@linuxfoundation.org; a=openpgp; fpr=F4B60CC5BF78C2214A313DCB3147D40DDB2DFB29 Precedence: bulk List-ID: X-Mailing-List: linux-mmc@vger.kernel.org When calling dev_set_name() memory is allocated for the name for the struct device. Once that structure device is registered, or attempted to be registerd, with the driver core, the driver core will handle cleaning up that memory when the device is removed from the system. Unfortunatly for the memstick code, there is an error path that causes the struct device to never be registered, and so the memory allocated in dev_set_name will be leaked. Fix that leak by manually freeing it right before the memory for the device is freed. Cc: Maxim Levitsky Cc: Alex Dubov Cc: Ulf Hansson Cc: "Rafael J. Wysocki" Cc: Hans de Goede Cc: Kay Sievers Cc: linux-mmc@vger.kernel.org Fixes: 0252c3b4f018 ("memstick: struct device - replace bus_id with dev_name(), Cc: stable Co-developed-by: Greg Kroah-Hartman Signed-off-by: Greg Kroah-Hartman Co-developed-by: Mirsad Goran Todorovac --- RESEND as the first version had a corrupted message id and never made it to the mailing lists or lore.kernel.org drivers/memstick/core/memstick.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/drivers/memstick/core/memstick.c b/drivers/memstick/core/memstick.c index bf7667845459..bbfaf6536903 100644 --- a/drivers/memstick/core/memstick.c +++ b/drivers/memstick/core/memstick.c @@ -410,6 +410,7 @@ static struct memstick_dev *memstick_alloc_card(struct memstick_host *host) return card; err_out: host->card = old_card; + kfree_const(card->dev.kobj.name); kfree(card); return NULL; } @@ -468,8 +469,10 @@ static void memstick_check(struct work_struct *work) put_device(&card->dev); host->card = NULL; } - } else + } else { + kfree_const(card->dev.kobj.name); kfree(card); + } } out_power_off: