From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-lj1-f177.google.com (mail-lj1-f177.google.com [209.85.208.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AC36A38B122 for ; Wed, 15 Apr 2026 13:00:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.177 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776258048; cv=none; b=azMGrCfQNJtwcpCybpyuPd2yey00982QgZ+EN02IPdvkL3c1n3f1AnQWXO44Suwodm7l9zAyqvmPjZaECYU4qMI5xIJgjjs1IpUerwYp+qVI/Hijaucf3nMOkRrZwD4Zr0r7JFsML5zT/p7nVLpUllS5ZUoTLL1Ua+DE02Yzsdc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776258048; c=relaxed/simple; bh=35BPFHRsAyeryQP2wvqeIo4z1K6AcrSpVNIQgcBWGjA=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=k3/Jp4Ice33aLvrouIKeH7DGo6ViWRzPlvZZTZhucAAv/iVgMDvt6KNioYNyaAPg5mtQYjnHepcibzUJLrCTeArdCMkrGC00vpi9nkwu0vRtr6aql91Sz29BjkoNvfuvEoa9iN15svNROtfpXiMlr4z2inTrN26M+jycRmgStEY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=linux.com; spf=pass smtp.mailfrom=gmail.com; arc=none smtp.client-ip=209.85.208.177 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=linux.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-lj1-f177.google.com with SMTP id 38308e7fff4ca-38e7d983f79so29502711fa.0 for ; Wed, 15 Apr 2026 06:00:46 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1776258045; x=1776862845; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:reply-to:user-agent:mime-version:date :message-id:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=QgomoS20HLCqI2HEt2xjHn1d0Vkw6fKblazGndW4B0c=; b=BGhsdXZnCjflklQzuzuN5j39kU/BeTAoBqiutHPHSWIzsOOEH+wQNxZWak6/QIP2tr zqfPMINVf3EFduwc6an04P5KGBseTj6Nmh0/cuEPc6V/Cyz62iP8iLqggzuKp6e6CnsC Onhkyp4/WA+xGEPx5MyuaESl38t6Qc5b72XajHdJF2Bv6U0Dqrc5X3pQWRzLQSiSQyH9 KCj1gQM0TobCuiQbITezGeWy1RTz6ZRaVnX6+r/CqXidEZ1Bsmkn+eX5JaQn4dX8aOqP hpG/iwWDiwMz7Hn+YaaehbOcUdxnmkXPHzrb4D+8rGzx8H9y7QUoqeBmUYfLtiLnzf4n Jhvg== X-Forwarded-Encrypted: i=1; AFNElJ/jBwTjoVn85CqscwsaenDiOKJUKos9TUg8Vc9WTPLrtnI5gpm1di2APsD5pKQJ20MiWmchTlunUK8ewmA=@vger.kernel.org X-Gm-Message-State: AOJu0Yx+n6Y9ZfUZK3PaPeoEKcE1erx5b+McvxHNLovYMue0FL9e3jTx KPZppYUgNWKf7mZmpLSkR8LJsQ9ONQVsNbLdAZvpOuUYyFIzkDpLlu8kI9GGvg== X-Gm-Gg: AeBDievLkUUsehFUbsiLYPIUhWGxhEgiygnWozWW1bGx/j1M1fPGcapomnyhYWJ4TTE xQFjl8hHWNlbLdw28yZjhw6zwAAOkbdIOD+XByuo+ETKpdbGM42GWmm8ci4uoXmFo8/HaMjkAOX XGsyNpYzDR2VM+TxRAfJOQ3lZAHtEZlI6Qk9WV8l2bj3cKfWWDY8MPPEiNMsL0OP16/YVYaZx4V rtvW1B2+VnKm559mnmN1iRC7Jz5q/TMOzDrQ0Omx8cOOTxokbJKJjGCgtsQwtVOa6Hr9qs64XNO aVKthb7MGsgLvU0FSF1e0iTqLnDJSxLR2NQ9h5LpScUASJM6cv/hZKuvkQ3P/3ss86uQhYBB9oK BtITm2m5LQSfdPEiKNK7Ki5TBu2ClEsKUR4NCHMcUf8Nh+oRzJQA0rIRV4mU5SG5+AdGezyvu4n b9nrvZ9imGJ18Di+SL6M5Gm3ftVmIz/ER46eDELKSM49gHiX7SUCycHCRKCUTgQpT5I1io X-Received: by 2002:a2e:9fcb:0:b0:385:9b50:91a8 with SMTP id 38308e7fff4ca-38e4beea127mr72404191fa.15.1776258044331; Wed, 15 Apr 2026 06:00:44 -0700 (PDT) Received: from [10.68.32.41] (bba-86-97-226-202.alshamil.net.ae. [86.97.226.202]) by smtp.gmail.com with ESMTPSA id 38308e7fff4ca-38e9e9b83f4sm4070891fa.9.2026.04.15.06.00.42 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 15 Apr 2026 06:00:43 -0700 (PDT) Message-ID: <8afc6b6b-399e-4f77-82e8-3c0e717f765e@linux.com> Date: Wed, 15 Apr 2026 17:00:39 +0400 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Reply-To: efremov@linux.com Subject: Re: [PATCH] floppy: fix reference leak on platform_device_register() failure To: Guangshuo Li , Jens Axboe , Greg Kroah-Hartman , linux-block@vger.kernel.org, linux-kernel@vger.kernel.org Cc: stable@vger.kernel.org References: <20260413153114.3040093-1-lgs201920130244@gmail.com> Content-Language: en-US, ru-RU From: "Denis Efremov (Oracle)" In-Reply-To: <20260413153114.3040093-1-lgs201920130244@gmail.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Hello, Thank you for the patch, On 13/04/2026 19:31, Guangshuo Li wrote: > When platform_device_register() fails in do_floppy_init(), the embedded > struct device in floppy_device[drive] has already been initialized by > device_initialize(), but the failure path jumps to out_remove_drives > without dropping the device reference for the current drive. > > Previously registered floppy devices are cleaned up in out_remove_drives, > but the device for the drive that fails registration is not, leading to > a reference leak. > > The issue was identified by a static analysis tool I developed and > confirmed by manual review. Fix this by calling put_device() for the > current floppy device before jumping to the common cleanup path. > > Fixes: 94fd0db7bfb4a ("[PATCH] Floppy: Add cmos attribute to floppy driver") > Cc: stable@vger.kernel.org > Signed-off-by: Guangshuo Li > --- > drivers/block/floppy.c | 4 +++- > 1 file changed, 3 insertions(+), 1 deletion(-) > > diff --git a/drivers/block/floppy.c b/drivers/block/floppy.c > index c28786e0fe1c..d9afe495d5c2 100644 > --- a/drivers/block/floppy.c > +++ b/drivers/block/floppy.c > @@ -4724,8 +4724,10 @@ static int __init do_floppy_init(void) > floppy_device[drive].dev.groups = floppy_dev_groups; > > err = platform_device_register(&floppy_device[drive]); > - if (err) > + if (err) { > + put_device(&floppy_device[drive].dev); 1. Let's use platform_device_put() > goto out_remove_drives; > + } > > registered[drive] = true; > err = device_add_disk(&floppy_device[drive].dev, disks[drive][0], NULL); if (err) goto out_remove_drives; 2. We also need to fix this case. platform_device_unregister() registered[drive] = false; goto ... Thanks, Denis