[{"id":3685791,"web_url":"http://patchwork.ozlabs.org/comment/3685791/","msgid":"<87a4ufs2cf.fsf@bootlin.com>","list_archive_url":null,"date":"2026-05-04T13:58:56","subject":"Re: [PATCH 3/5] mtd: maps: physmap: fix reference leak on failed\n device registration","submitter":{"id":73368,"url":"http://patchwork.ozlabs.org/api/people/73368/","name":"Miquel Raynal","email":"miquel.raynal@bootlin.com"},"content":"On 04/05/2026 at 13:08:45 +03, Vastargazing <vebohr@gmail.com> wrote:\n\n> When platform_device_register() fails in physmap_init(), the embedded\n> struct device has already been initialized by device_initialize() inside\n> platform_device_register(). The error path unregisters the driver but\n> returns without dropping the device reference:\n>\n>   physmap_init()\n>     -> platform_device_register(&physmap_flash)\n>        -> device_initialize(&physmap_flash.dev)   /* kref = 1 */\n>        -> platform_device_add(&physmap_flash)     /* fails */\n>     <- platform_driver_unregister() called, but kref still 1\n>\n> Per platform_device_register() kernel-doc:\n>\n>   NOTE: _Never_ directly free @pdev after calling this function, even if\n>   it returned an error! Always use platform_device_put() to give up the\n>   reference initialised in this function instead.\n>\n> Fix this by calling platform_device_put() before unregistering the driver.\n>\n> Fixes: 73566edf9b91 (\"[MTD] Convert physmap to platform driver\")\n> Cc: stable@vger.kernel.org\n> Assisted-by: GitHub Copilot (Claude Sonnet 4.5)\n> Signed-off-by: Vastargazing <vebohr@gmail.com>\n\nSomehow b4 applied another patch from that series, I'm not sure why. I\njust dropped it. Please resend this patch alone.\n\nAlso, your SoB line seems to be incorrect, we need a proper name, please\nhave a loot at the DCO.\n\nThanks,\nMiquèl","headers":{"Return-Path":"\n <linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org>","X-Original-To":"incoming@patchwork.ozlabs.org","Delivered-To":"patchwork-incoming@legolas.ozlabs.org","Authentication-Results":["legolas.ozlabs.org;\n\tdkim=pass (2048-bit key;\n secure) header.d=lists.infradead.org header.i=@lists.infradead.org\n header.a=rsa-sha256 header.s=bombadil.20210309 header.b=3EJgqUGo;\n\tdkim=fail reason=\"signature verification failed\" (2048-bit key;\n unprotected) header.d=bootlin.com header.i=@bootlin.com header.a=rsa-sha256\n header.s=dkim header.b=KOoBPuZ8;\n\tdkim-atps=neutral","legolas.ozlabs.org;\n spf=none (no SPF record) smtp.mailfrom=lists.infradead.org\n (client-ip=2607:7c80:54:3::133; helo=bombadil.infradead.org;\n envelope-from=linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org;\n receiver=patchwork.ozlabs.org)"],"Received":["from bombadil.infradead.org (bombadil.infradead.org\n [IPv6:2607:7c80:54:3::133])\n\t(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n\t key-exchange x25519 server-signature ECDSA (secp384r1) server-digest SHA384)\n\t(No client certificate requested)\n\tby legolas.ozlabs.org (Postfix) with ESMTPS id 4g8NYD3WLBz1yJ0\n\tfor <incoming@patchwork.ozlabs.org>; Mon, 04 May 2026 23:59:12 +1000 (AEST)","from localhost ([::1] helo=bombadil.infradead.org)\n\tby bombadil.infradead.org with esmtp (Exim 4.98.2 #2 (Red Hat Linux))\n\tid 1wJtpC-0000000DN4t-1Kry;\n\tMon, 04 May 2026 13:59:06 +0000","from smtpout-03.galae.net ([185.246.85.4])\n\tby bombadil.infradead.org with esmtps (Exim 4.98.2 #2 (Red Hat Linux))\n\tid 1wJtp8-0000000DN44-3n3V\n\tfor linux-mtd@lists.infradead.org;\n\tMon, 04 May 2026 13:59:05 +0000","from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233])\n\tby smtpout-03.galae.net (Postfix) with ESMTPS id 9A7974E42BB8;\n\tMon,  4 May 2026 13:58:59 +0000 (UTC)","from mail.galae.net (mail.galae.net [212.83.136.155])\n\tby smtpout-01.galae.net (Postfix) with ESMTPS id 69A915FD5F;\n\tMon,  4 May 2026 13:58:59 +0000 (UTC)","from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon)\n with ESMTPSA id B737E11AD2449;\n\tMon,  4 May 2026 15:58:56 +0200 (CEST)"],"DKIM-Signature":["v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed;\n\td=lists.infradead.org; s=bombadil.20210309; h=Sender:\n\tContent-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post:\n\tList-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-ID:Date:References\n\t:In-Reply-To:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description:\n\tResent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:\n\tList-Owner; bh=ktPifTi9DLNjjXVFe+3bhq8GpeZy6rIKrFzctuXgsdw=; b=3EJgqUGo8BVbQ4\n\tonLKm5fIIruesVUeFoupxVoN8CcQIiiOnoCBswO/RZPyM35T+65eRB0C8Vvw6pLK5wO3I0CQ3m9iG\n\tpCFcy7yxRTCBYW3NpiA11aAW5mgv7B4kMSYwV+W9WBT80iK2j21QmPGxhCE3O6s/MhByfCRjrJihg\n\tBb0TfHm4WreGVIIkJ2k6msMI+QQHzvzuwhqNIvTwn0wpK/bxdSilojaA8usLneGzL+835wtW0xVR8\n\tb4aTeaHPs0RJPxEASd8jeJJw39rc+KDkIR/gIaWHM1ebgJwclhJiACb1Sjre6rgayxE383hiTqN7S\n\tzr+YihhSQxIgYg5fjung==;","v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim;\n\tt=1777903138; h=from:subject:date:message-id:to:cc:mime-version:content-type:\n\t content-transfer-encoding:in-reply-to:references;\n\tbh=LVrH+hRa8k60712RPQs7XAU8jqIwLgDkBraOs0In2Cc=;\n\tb=KOoBPuZ8iPsqVJviZXRPur58W4+JFX2f+4e1Yw2f62tBEjd3M/aDEw1paPJy7ALa2H3qiA\n\tDGBZfFGDu+PCKMTqLGRCgqsBPtOg1zI1apECUFvNwyW230zpPrzczAmwnBusuwnnuy013J\n\tDEqVNFYwkAK1wsTRcLzbxR8X1ApVq6zAPansft6cn28IfpDvJAssHkX1K4JAI8Q1rJyH43\n\t/dQjB7cGMcrekjEwPSLABk+OXXQrbsvrkLjNMzgcHmqj5o+bwQZl9MFV8+Lyy/P48PmpzD\n\teQFYHcXKEOasY8/e7LJtXeMmbBDmJxda19p/PwuSTJtn6SjuYp6cKX9CtVUGxg=="],"From":"Miquel Raynal <miquel.raynal@bootlin.com>","To":"Vastargazing <vebohr@gmail.com>","Cc":"linux-kernel@vger.kernel.org,  stable@vger.kernel.org,  Richard\n Weinberger <richard@nod.at>,  Vignesh Raghavendra <vigneshr@ti.com>,\n  David Woodhouse <dwmw2@infradead.org>,  Lennert Buytenhek\n <buytenh@wantstofly.org>,  linux-mtd@lists.infradead.org","Subject":"Re: [PATCH 3/5] mtd: maps: physmap: fix reference leak on failed\n device registration","In-Reply-To":"\n <6717e0b2a6244ee4e691dba03eb8c790c202e89e.1777889235.git.vebohr@gmail.com>\n\t(Vastargazing's message of \"Mon, 4 May 2026 13:08:45 +0300\")","References":"<cover.1777889235.git.vebohr@gmail.com>\n\t<6717e0b2a6244ee4e691dba03eb8c790c202e89e.1777889235.git.vebohr@gmail.com>","User-Agent":"mu4e 1.12.7; emacs 30.2","Date":"Mon, 04 May 2026 15:58:56 +0200","Message-ID":"<87a4ufs2cf.fsf@bootlin.com>","MIME-Version":"1.0","X-Last-TLS-Session-Version":"TLSv1.3","X-CRM114-Version":"20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 ","X-CRM114-CacheID":"sfid-20260504_065903_080909_C9A9171D ","X-CRM114-Status":"GOOD (  11.97  )","X-Spam-Score":"-2.1 (--)","X-Spam-Report":"Spam detection software,\n running on the system \"bombadil.infradead.org\",\n has NOT identified this incoming email as spam.  The original\n message has been attached to this so you can view it or label\n similar future email.  If you have any questions, see\n the administrator of that system for details.\n Content preview:  On 04/05/2026 at 13:08:45 +03,\n Vastargazing <vebohr@gmail.com>\n    wrote: > When platform_device_register() fails in physmap_init(),\n the embedded\n    > struct device has already been initialized by device_initialize() inside\n    > platform_device_register(). The error path unregist [...]\n Content analysis details:   (-2.1 points, 5.0 required)\n  pts rule name              description\n ---- ----------------------\n --------------------------------------------------\n -0.0 SPF_PASS               SPF: sender matches SPF record\n -0.0 SPF_HELO_PASS          SPF: HELO matches SPF record\n  0.1 DKIM_SIGNED            Message has a DKIM or DK signature,\n not necessarily valid\n -0.1 DKIM_VALID_AU          Message has a valid DKIM or DK signature from\n author's\n                             domain\n -0.1 DKIM_VALID             Message has at least one valid DKIM or DK\n signature\n -0.1 DKIM_VALID_EF          Message has a valid DKIM or DK signature from\n                             envelope-from domain\n -1.9 BAYES_00               BODY: Bayes spam probability is 0 to 1%\n                             [score: 0.0000]","X-BeenThere":"linux-mtd@lists.infradead.org","X-Mailman-Version":"2.1.34","Precedence":"list","List-Id":"Linux MTD discussion mailing list <linux-mtd.lists.infradead.org>","List-Unsubscribe":"<http://lists.infradead.org/mailman/options/linux-mtd>,\n <mailto:linux-mtd-request@lists.infradead.org?subject=unsubscribe>","List-Archive":"<http://lists.infradead.org/pipermail/linux-mtd/>","List-Post":"<mailto:linux-mtd@lists.infradead.org>","List-Help":"<mailto:linux-mtd-request@lists.infradead.org?subject=help>","List-Subscribe":"<http://lists.infradead.org/mailman/listinfo/linux-mtd>,\n <mailto:linux-mtd-request@lists.infradead.org?subject=subscribe>","Content-Type":"text/plain; charset=\"utf-8\"","Content-Transfer-Encoding":"base64","Sender":"\"linux-mtd\" <linux-mtd-bounces@lists.infradead.org>","Errors-To":"linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org"}}]