From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-lf1-f48.google.com (mail-lf1-f48.google.com [209.85.167.48]) (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 070233B389E for ; Wed, 15 Apr 2026 14:16:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.48 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776262563; cv=none; b=JAjHMidRNz1D8OtfAkrr1eQpL6mtC71P+uhuNaWLMPu/ceUTjs/GvqTN7eL/KzqPghvCKOvHfaq512VGEeOitlbhNhD2QTTAHykE4QRdi2PQzg/kQMsHBf6GBgxj9pjMoSvysmCVCGD4idN1tTFkxrIIyRIpdbfr8pX7/cOGRlw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776262563; c=relaxed/simple; bh=Pdy7Mh+hnfOvCQDqW76dEUcz37KcOEmwFbjUwviC6ew=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=Nu1zCIKgxhJHBHET+6C6N7m9QM9TWxWbL2+CNgDz7rGnv6qe8IFQ3E7lSnJj+ab79WK9OCXO3Vwzd0F9Q5O7GrpqYLtThR8BmuH3pOMmrAn7sm6XwPCFjz+iAY49ZDaUNGGuxsijKPgCQb6DRIkkUltaV/Xq2BXj6Te+PHRemf0= 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.167.48 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-lf1-f48.google.com with SMTP id 2adb3069b0e04-5a337552604so5967872e87.2 for ; Wed, 15 Apr 2026 07:16:01 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1776262560; x=1776867360; 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=A9GVK3912ykSKoEN3+mlTPV6LfdyMXA4vXMmtRCWPRU=; b=ntb0aPGn/+JujLDVqR48rR7raq91Yod/KToOAyG2cSVMCqeyjj7IPGI7SQd/6vjOrq 6G00Q8BN9DtP9Po5+H88T+j9IGV4Y9U1uPSlAfoFwik8agLYs1NRVnJv90FbgxZh9TXi q4CyjpthjGxj2EGSQmb4irLB/ChNIigkYJzLZacF8k/E7r+y8FHmMPhU6nCr1XKAYPRm bF9hRBmOuRqN5/eulpK2wSYkDtFazVCi/oCQN1eMlzj2voDqNfOTazl2m3Hmt3JiYzCo 0429uk2acf92TwWJFOFBP70SE2RO6CF4KmNb0OVtwYmSYB48SFJ+2T10s+cWTT4V44sm uxPg== X-Forwarded-Encrypted: i=1; AFNElJ9Tddmt2kEs3RZWNVG/FEu5uf9vjI47HjuKtjwa7ZnoWAm/QLibKz/LwZn1bgdEbx3+dj24Yi7n0fb8imk=@vger.kernel.org X-Gm-Message-State: AOJu0YzvMQ/Z/nnAvwfmf/+j+o+o5OUIllR1bKNVP0xkpScBZ3P6Gjbb 8ls3cqxxgGiqvrFAHunsUSTGOMNJJhZrUzoLYH4dRp0iqDiqnoyrtUkcDUTB2g== X-Gm-Gg: AeBDievBBCIStFcIazVLLB/E3lyWausoiJd1Z7L9470cDNc57TX3wD7jlCgpyha4IZh goygEWIRbuAb58QAEr/XhZ7bMpN7Gx4GtK22efGKUtKBodLJVrbv9bv5bxMVPGu+vlny6eYyzdx uONJF8Q6bQjo9SNrXw0CuT3Oc4tctkNKUWqHwjG5Hwt7ewyDcK72+u95WrrI07hbLhuygL/zxvG MaTF2+66q0KB0WTjJYyOyQRIi3wk5kgfJELD7MsMtDZ/RW1/1SnJhIYxzUNLI1uZRs+HONN2SXt Cs7eiiD7/VjY7xz7RLZdwss9z2HVptGkCn0WoD97aZdOSvh4fp8Z8RVaiJ+l/6wVApfm7qvcPjr XyVbOZdNDJ09TzEjVgaejofFin92GruHXdHQVW7BDGtgfi0SsQqHEHJEeJE08VmXfQe4iBJW1iw lPJnI2ntS1aLyIMFM5knkn1r+4PiU63lqp+/MowVKl+OnZxCbKSyXhd8fUDaL9LvStJVlBpuxjx a7NSB0= X-Received: by 2002:a05:6512:6cb:b0:5a4:50:ac71 with SMTP id 2adb3069b0e04-5a40050adafmr3650399e87.13.1776262559949; Wed, 15 Apr 2026 07:15:59 -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 2adb3069b0e04-5a40a2e71absm503650e87.46.2026.04.15.07.15.58 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 15 Apr 2026 07:15:59 -0700 (PDT) Message-ID: <376f0e18-fae3-45d7-b3bf-885e963e6b51@linux.com> Date: Wed, 15 Apr 2026 18:15:56 +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 Cc: Jens Axboe , Greg Kroah-Hartman , linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org References: <20260413153114.3040093-1-lgs201920130244@gmail.com> <8afc6b6b-399e-4f77-82e8-3c0e717f765e@linux.com> Content-Language: en-US, ru-RU From: "Denis Efremov (Oracle)" In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit On 15/04/2026 17:54, Guangshuo Li wrote: > Hi Denis, > > Thank you for the review. > > On Wed, 15 Apr 2026 at 21:00, Denis Efremov (Oracle) wrote: >> >> 1. Let's use platform_device_put() >> >>> goto out_remove_drives; >>> + } >>> >>> registered[drive] = true; >>> > > My understanding is: > > For the platform_device_register() failure case, we should use > platform_device_put() instead of put_device(), so the failure path > would look like: > > err = platform_device_register(&floppy_device[drive]); > if (err) { > platform_device_put(&floppy_device[drive]); > goto out_remove_drives; > } > registered[drive] = true; Yes, correct. > >> 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 > We also need to handle the device_add_disk() failure case for the > current drive, since out_remove_drives only cleans up previously > registered drives. So this path should explicitly unregister the > current platform device before jumping to the common cleanup path, for > example: > > err = device_add_disk(&floppy_device[drive].dev, disks[drive][0], NULL); > if (err) { > platform_device_unregister(&floppy_device[drive]); > registered[drive] = false; > goto out_remove_drives; > } > > > Is my understanding correct? If so, I will prepare and send a v2 > following this pattern. Yes, correct. Please, send v2. > > Thanks, > Guangshuo