From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DB8173BF314; Thu, 15 Jan 2026 17:13:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768497183; cv=none; b=O5tCrP1IVTUic4/f2Rwm82uCQIcZDAXK+PoH5A+j90qwpPKlvDc8XKHff+O8rkuJDkN6fvSzoU05z2PPc4y0uW+z4gORLvomjQ2nHrI4z8+9Er6BksAijcFkbA8AfqlMoeNrPRKUhCKau6D7+fN4Qpk9W1jTTkO4GEceszoNqCg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768497183; c=relaxed/simple; bh=1xT/9p3lWfQHLRazF1RGc72QcejEbpE0eq8maBAFFYo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=VPBSg+6+9C633ru7t8ZLqpnuC1/pX3YveeX+Tk9GjlrKEVOTvZ9Rapvq6XWeE+mbijHiElmAWD0nzGptmycmBVHe8+8Acy3JMufaiIy9zREN76SiIHS8OHXRXidy4cGMEqj45fIGQ2KZGUrX2ULAqbaxjFPRSo/jWbPOhVQmxLw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=AOD0XFkl; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="AOD0XFkl" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 68E23C116D0; Thu, 15 Jan 2026 17:13:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1768497183; bh=1xT/9p3lWfQHLRazF1RGc72QcejEbpE0eq8maBAFFYo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=AOD0XFkl+SlDOZaBTEZwfRU/XQAjESXHwXcDRNd7JksBz1HA8D0RnilicJKYkf44s NICDTcUDP8ZeDrqcVgKW/cse9SnjBYRkxHtBh9/afhu2dFzhcKYuioqgHft5VHzgQu 09weKBGOlywj7MqWxwt5ubx4GiC22EhPK0Qf7nSw= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Sumeet Pawnikar , "Rafael J. Wysocki" , Sasha Levin Subject: [PATCH 6.1 66/72] powercap: fix race condition in register_control_type() Date: Thu, 15 Jan 2026 17:49:16 +0100 Message-ID: <20260115164145.896617587@linuxfoundation.org> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260115164143.482647486@linuxfoundation.org> References: <20260115164143.482647486@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.1-stable review patch. If anyone has any objections, please let me know. ------------------ From: Sumeet Pawnikar [ Upstream commit 7bda1910c4bccd4b8d4726620bb3d6bbfb62286e ] The device becomes visible to userspace via device_register() even before it fully initialized by idr_init(). If userspace or another thread tries to register a zone immediately after device_register(), the control_type_valid() will fail because the control_type is not yet in the list. The IDR is not yet initialized, so this race condition causes zone registration failure. Move idr_init() and list addition before device_register() fix the race condition. Signed-off-by: Sumeet Pawnikar [ rjw: Subject adjustment, empty line added ] Link: https://patch.msgid.link/20251205190216.5032-1-sumeet4linux@gmail.com Signed-off-by: Rafael J. Wysocki Signed-off-by: Sasha Levin --- drivers/powercap/powercap_sys.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/drivers/powercap/powercap_sys.c b/drivers/powercap/powercap_sys.c index fd475e463d1fa..d7dadcaa3736b 100644 --- a/drivers/powercap/powercap_sys.c +++ b/drivers/powercap/powercap_sys.c @@ -624,17 +624,23 @@ struct powercap_control_type *powercap_register_control_type( INIT_LIST_HEAD(&control_type->node); control_type->dev.class = &powercap_class; dev_set_name(&control_type->dev, "%s", name); - result = device_register(&control_type->dev); - if (result) { - put_device(&control_type->dev); - return ERR_PTR(result); - } idr_init(&control_type->idr); mutex_lock(&powercap_cntrl_list_lock); list_add_tail(&control_type->node, &powercap_cntrl_list); mutex_unlock(&powercap_cntrl_list_lock); + result = device_register(&control_type->dev); + if (result) { + mutex_lock(&powercap_cntrl_list_lock); + list_del(&control_type->node); + mutex_unlock(&powercap_cntrl_list_lock); + + idr_destroy(&control_type->idr); + put_device(&control_type->dev); + return ERR_PTR(result); + } + return control_type; } EXPORT_SYMBOL_GPL(powercap_register_control_type); -- 2.51.0