Received: by 2002:a05:6358:a55:b0:ec:fcf4:3ecf with SMTP id 21csp3166205rwb; Fri, 20 Jan 2023 12:08:22 -0800 (PST) X-Google-Smtp-Source: AMrXdXt9kMl6u1qO4J9GnKszLFx0cFvfhSLGnmWMlEkihPNdMYZ/F37TUeqitr/rDG36iMLax2c1 X-Received: by 2002:a17:906:944a:b0:7c1:23f2:5b51 with SMTP id z10-20020a170906944a00b007c123f25b51mr26876054ejx.60.1674245302402; Fri, 20 Jan 2023 12:08:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674245302; cv=none; d=google.com; s=arc-20160816; b=u4Jnxk0Ggsk+r1Qj5Ob5ZGhwe9AhFrAlSIyfAVq02zYSvz9UfhYTLeio2nfeIbDYPl eIX9GGiug9XoTZ6jy8VlgwHtEOhPdM1UsGHoYe4FRRIZrUOHexpL7ut6dHRKMYJy/g0/ 3ogB0VeiL/fZoNwM03j/gV0LbAFUOVh6CdRnfQKXk4PFCf99FLf9VvTVX9Pv6qBlIlbl 1ies8x5VpTkk0uE7pMnPAmwOvcnEM98cMxMr/7O6CGpNB/9+5WaU74WG0in6X+BYJYeV Y2UnO1cLJnfbJ4RLAJ2p0xztvNuCuZG0XtFDxj0k+Ne94GWfaXGwVB7h2QI5sY8raeUj htkQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=HnhHu5LhqMmGYYd2Ig8Jgsi2CkbpClLdafJuyqZpPNc=; b=mXUxc/mJDqmu3sKwgo/oLbHKf75u07GeYlghU2iB6HSiHnBn87ZW+abCsao/rfJmaA q2f2ObVPmG1YFYAFtJQwx6+J/JwnS3WwevmZk7jOx79/X6P+3/g6BYRtqMNeMglbw0LT XREx/mBvyXxEei94XRzpB7VwiTD/LpiFsBvZD/q7fhX3z48z9f8FwgGYeWrsusYH1Jz2 RRJ/WGvDmCfuPEq1AKVCf1dF9Z0RhU8xVyDf1uXZxdbqR6qMCt3R6k43MFbYxOFUI2kl f+XAjJauvUcyEuv/E+HUmbrErqNO2f47tKPBVPcmv+XuinwLSiQctiLcEsnYM/8R+lRu Wv6g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id dt4-20020a170907728400b00871dfbabf41si15533600ejc.272.2023.01.20.12.07.47; Fri, 20 Jan 2023 12:08:22 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229824AbjATTs7 (ORCPT + 50 others); Fri, 20 Jan 2023 14:48:59 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42400 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229910AbjATTsn (ORCPT ); Fri, 20 Jan 2023 14:48:43 -0500 Received: from cloudserver094114.home.pl (cloudserver094114.home.pl [79.96.170.134]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1D3A59373F; Fri, 20 Jan 2023 11:48:33 -0800 (PST) Received: from localhost (127.0.0.1) (HELO v370.home.net.pl) by /usr/run/smtp (/usr/run/postfix/private/idea_relay_lmtp) via UNIX with SMTP (IdeaSmtpServer 5.1.0) id f845a5482e773122; Fri, 20 Jan 2023 20:48:32 +0100 Received: from kreacher.localnet (unknown [213.134.183.98]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by v370.home.net.pl (Postfix) with ESMTPSA id 7256E23101AB; Fri, 20 Jan 2023 20:48:31 +0100 (CET) From: "Rafael J. Wysocki" To: Linux PM , Greg Kroah-Hartman Cc: LKML , Daniel Lezcano , Srinivas Pandruvada , Zhang Rui Subject: [PATCH v1 1/2] driver core: class: Clear private pointer on registration failures Date: Fri, 20 Jan 2023 20:46:57 +0100 Message-ID: <4463268.LvFx2qVVIh@kreacher> In-Reply-To: <5905717.lOV4Wx5bFT@kreacher> References: <5905717.lOV4Wx5bFT@kreacher> MIME-Version: 1.0 Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="UTF-8" X-CLIENT-IP: 213.134.183.98 X-CLIENT-HOSTNAME: 213.134.183.98 X-VADE-SPAMSTATE: clean X-VADE-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgedvhedrudduvddgudefvdcutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfjqffogffrnfdpggftiffpkfenuceurghilhhouhhtmecuudehtdenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujfgurhephffvvefufffkjghfggfgtgesthfuredttddtjeenucfhrhhomhepfdftrghfrggvlhculfdrucghhihsohgtkhhifdcuoehrjhifsehrjhifhihsohgtkhhirdhnvghtqeenucggtffrrghtthgvrhhnpeetkeeigfegjeevudelvdejvdetteehleekjeegkeejiedvlefgheehieehgedugfenucffohhmrghinhepkhhosghjrdhnrghmvgenucfkphepvddufedrudefgedrudekfedrleeknecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehinhgvthepvddufedrudefgedrudekfedrleekpdhhvghlohepkhhrvggrtghhvghrrdhlohgtrghlnhgvthdpmhgrihhlfhhrohhmpedftfgrfhgrvghlucflrdcuhgihshhotghkihdfuceorhhjfiesrhhjfiihshhotghkihdrnhgvtheqpdhnsggprhgtphhtthhopeeipdhrtghpthhtoheplhhinhhugidqphhmsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtohepghhrvghgkhhhsehlihhnuhigfhhouhhnuggrthhiohhnrdhorhhgpdhrtghpthhtoheplhhinhhugidqkhgvrhhnvghlsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtohepuggrnhhivghlrdhl vgiitggrnhhosehlihhnrghrohdrohhrghdprhgtphhtthhopehsrhhinhhivhgrshdrphgrnhgurhhuvhgruggrsehlihhnuhigrdhinhhtvghlrdgtohhmpdhrtghpthhtoheprhhuihdriihhrghnghesihhnthgvlhdrtghomh X-DCC--Metrics: v370.home.net.pl 1024; Body=6 Fuz1=6 Fuz2=6 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Rafael J. Wysocki Clear the class private pointer if __class_register() fails for it, so as to allow its users to verify that the class is usable by checking the value of that pointer. For consistency, clear that pointer before freeing the object pointed to by it in class_release(). Signed-off-by: Rafael J. Wysocki --- drivers/base/class.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) Index: linux-pm/drivers/base/class.c =================================================================== --- linux-pm.orig/drivers/base/class.c +++ linux-pm/drivers/base/class.c @@ -53,6 +53,8 @@ static void class_release(struct kobject pr_debug("class '%s': release.\n", class->name); + class->p = NULL; + if (class->class_release) class->class_release(class); else @@ -186,17 +188,21 @@ int __class_register(struct class *cls, cls->p = cp; error = kset_register(&cp->subsys); - if (error) { - kfree(cp); - return error; - } + if (error) + goto err_out; + error = class_add_groups(class_get(cls), cls->class_groups); class_put(cls); if (error) { kobject_del(&cp->subsys.kobj); kfree_const(cp->subsys.kobj.name); - kfree(cp); + goto err_out; } + return 0; + +err_out: + kfree(cp); + cls->p = NULL; return error; } EXPORT_SYMBOL_GPL(__class_register);