Received: by 2002:a05:7412:d1aa:b0:fc:a2b0:25d7 with SMTP id ba42csp20437rdb; Wed, 31 Jan 2024 22:07:30 -0800 (PST) X-Google-Smtp-Source: AGHT+IFiedGZAf0bb/Fi0XM0R6/M2G44ZflpUUBv7uF8tSkBvL9ls60X7Jq7Vrkmc4bHOO4P18GH X-Received: by 2002:a17:906:190a:b0:a28:2165:7c74 with SMTP id a10-20020a170906190a00b00a2821657c74mr2601136eje.13.1706767650156; Wed, 31 Jan 2024 22:07:30 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706767650; cv=pass; d=google.com; s=arc-20160816; b=QYEcy4j3L3FT78VddWGesqu5Purh6Yj/dKK158n60jxIwCMy6+N0YVydCfDanABQrI s2yXixdrioVq4bQ5fjI1zrDv0xPNXpXNgE/VB/r+1yIMUCBtYHgtow0hw5HYeH3Fkxxf zP9Rn9YRDUjNBWk5KyGhz3RdbUMrJLXi0zv6KZC7xAMtGWM08JSZal0FMbqlbu62Udy2 R5mfP9t+Tr7UA8KT2d6nBgam+q27fHsG5TEUPQq1/8LkWTAxx5+d1M1SdpBilVKbm4rW uEPCCvzu5lFk6KDmphdSksiFovdTdUXzs97Z6Bjxbs6b3u8iJ7q+HWMzo2jWDWzt0oBz n0lQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:from:subject:message-id:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:dkim-signature; bh=+R+QwEvKVG52HCupcuvyMyVixKSfMEwsPllchfsZTgU=; fh=1AYT39ktdx2DxrFhjlW+97QxV6UNewTTwG07FfhQwuQ=; b=fk6QSbNM4bPCKisU1KjRofoT1P6BW8P2cwCO+nPs4luAfVG/g8/L0MPkb4w4YmBNxu vD8HlONL/4QDTV1lThGJg3RDM1xfaPn7VHWfw2KsBzfQ0sH+m1N6EiV+GD0y3VGL+4AF S+WLctnf+CEbe5WtBfCPojgHxcXu9yI675bDAL1xde1x5V8BEycDXFy8KVpdHPHlpIUY +vc21LtdkkDC2Ovl7q9n7QmoWXI/lAiPAmZYq0pGjV80ShyEU4IXFpGDitLqh52jzC4l Yj+UEQT7YOxmk0plnXAYcm11YLMq47ePVVS3L2Q0njtMuMgjUr5POH3bUpdIicVMrSzy MF5w==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=0LY85O9h; arc=pass (i=1 spf=pass spfdomain=flex--davidgow.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-47684-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-47684-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com X-Forwarded-Encrypted: i=1; AJvYcCWtzkRiAGuGInYg0xOlM1afzgAfx9C0iDY0VHvU+GhSbFAziSr+6sHnPabliazNgdzGEHh67z8W0Zpn1VaKHXXquP0I7/zFgDS+tRLTJw== Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id k14-20020a170906054e00b00a365c4276efsi1720955eja.9.2024.01.31.22.07.30 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 31 Jan 2024 22:07:30 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-47684-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=0LY85O9h; arc=pass (i=1 spf=pass spfdomain=flex--davidgow.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-47684-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-47684-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id C573C1F27EBE for ; Thu, 1 Feb 2024 06:06:33 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D054684A24; Thu, 1 Feb 2024 06:06:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="0LY85O9h" Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.201]) (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 5678182D73 for ; Thu, 1 Feb 2024 06:06:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706767583; cv=none; b=KyysFRAgN99IwKAaOIodlByAAtTlmklL/I3Y/gTSnRvbG9IYQKRd90uTcnncnPoZ7gn2rMUb9iZl/X5O6IUyKIeGQ11mS3sX0PDD8GFrNGi/30KL/Hg0gj/MYVrWX7JNifpYOokXK6GMNpxCcgrZw/8ilQ/J7hMB3Igl2fTnTnA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706767583; c=relaxed/simple; bh=0LRxdChxLmKEhnOYVLzmM5OXlQ0XC+cmLb43Z7+cynM=; h=Date:Mime-Version:Message-ID:Subject:From:To:Cc:Content-Type; b=dcmSxHO/ffpVcYx2w0P6Q9MsyWQv1zqc98CGQXwYreR+N3+YKMUZIAiUyyCumU35WnyZfQytSeoWYIZ5gfUXzXL0XVwB/rD24kGTJzTNGXmmFuy9SgtUwBkwFhvw8uv6FGgd4DpGorzIZtoLbXtyzbJRgknCcUCIHC2ZeOQJ28Y= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--davidgow.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=0LY85O9h; arc=none smtp.client-ip=209.85.219.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--davidgow.bounces.google.com Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-dc6cd10fd4aso899352276.1 for ; Wed, 31 Jan 2024 22:06:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1706767581; x=1707372381; darn=vger.kernel.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=+R+QwEvKVG52HCupcuvyMyVixKSfMEwsPllchfsZTgU=; b=0LY85O9h72c4jUBvNZCjsSNl9tDmeiIwvLt7tNGNn6Z8suRSBZ01xM2oLDvhQrOIxO e8/rexbGGV6qLd3Vk+tFrDNDsI4CWhUh5VLUhearaVAHK08bcNrNoyCbt3Ed9T4sNe6/ fIbaThBUjiCGgL3fAOYQmKe2qJhORoWCKH9Th6ZoYpeHi5BMydYfVwTlFICLeqgRKq11 bn83jNXwX4FOHfEhRIWKG3IsRIbKDL76AvohXQWVErVhphEYmrKp5yx7K4Gtxf5uYMrS CX2GkKCQ6eEKHAYDIH5CTJxblIKi3S7qvFpAIPjTA3552Lhe9aYClLIfISAWQz/0Hu91 3dXQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706767581; x=1707372381; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=+R+QwEvKVG52HCupcuvyMyVixKSfMEwsPllchfsZTgU=; b=Z78uYBCJ/L/jMOqBSMu8D1kfwYcpJrlDCks9YTGFz8I5/IiLfLvfq6cErgOyLFVLBN EL9EZ1MN9t8/ZU8FXDo8BtFKxzd5lwxrNXyekrtWPT8VIb257rlWbuCsHDV2AQIp0iB6 t6k4WnNi5qbrhwVu0eag4yrU1uOM2sQ9kw7OcgEBQja40HdoDF1us0D+gn3P1Pc/a61C Y9dqsOtLF90UKupuLYryyIhigqxjEk+8VDH+jVCNjnLYCtUD5fa3ukDEqUT/TSV1oE9H cII8TIpzD3Y8PKkktUGt8p4TIrm84kphPu/wdKGnYtA8Taltd0Rhh5IPm+6vFJtv+uSW JxLA== X-Gm-Message-State: AOJu0Yx4Ni4Okkw4hLdlTtlsptaJg1FfAyoPavpSoYsX+gKYKHyTMVFv xSEZcyIdld22lk04R4K+QqMb/iWi+m1taTW5eppjGAOf4X4c0MG4gS3L1HUIfuFJrdkzdFrZ67k t6X+B77mM+A== X-Received: from slicestar.c.googlers.com ([fda3:e722:ac3:cc00:4f:4b78:c0a8:20a1]) (user=davidgow job=sendgmr) by 2002:a05:6902:1584:b0:dbe:387d:a8ef with SMTP id k4-20020a056902158400b00dbe387da8efmr41769ybu.1.1706767581338; Wed, 31 Jan 2024 22:06:21 -0800 (PST) Date: Thu, 1 Feb 2024 14:04:36 +0800 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 X-Mailer: git-send-email 2.43.0.429.g432eaa2c6b-goog Message-ID: <20240201060437.861155-2-davidgow@google.com> Subject: [PATCH] kunit: device: Unregister the kunit_bus on shutdown From: David Gow To: Rae Moar , Shuah Khan Cc: David Gow , Matti Vaittinen , Greg Kroah-Hartman , Brendan Higgins , Maxime Ripard , linux-kselftest@vger.kernel.org, kunit-dev@googlegroups.com, linux-kernel@vger.kernel.org, Borah@google.com, Chaitanya Kumar , Saarinen@google.com, Jani , Richard Fitzgerald , intel-gfx@lists.freedesktop.org Content-Type: text/plain; charset="UTF-8" If KUnit is built as a module, and it's unloaded, the kunit_bus is not unregistered. This causes an error if it's then re-loaded later, as we try to re-register the bus. Unregister the bus and root_device on shutdown, if it looks valid. In addition, be more specific about the value of kunit_bus_device. It is: - a valid struct device* if the kunit_bus initialised correctly. - an ERR_PTR if it failed to initialise. - NULL before initialisation and after shutdown. Fixes: d03c720e03bd ("kunit: Add APIs for managing devices") Signed-off-by: David Gow --- This will hopefully resolve some of the issues linked to from: https://lore.kernel.org/intel-gfx/DM4PR11MB614179CB9C387842D8E8BB40B97C2@DM4PR11MB6141.namprd11.prod.outlook.com/ --- lib/kunit/device-impl.h | 2 ++ lib/kunit/device.c | 14 ++++++++++++++ lib/kunit/test.c | 3 +++ 3 files changed, 19 insertions(+) diff --git a/lib/kunit/device-impl.h b/lib/kunit/device-impl.h index 54bd55836405..5fcd48ff0f36 100644 --- a/lib/kunit/device-impl.h +++ b/lib/kunit/device-impl.h @@ -13,5 +13,7 @@ // For internal use only -- registers the kunit_bus. int kunit_bus_init(void); +// For internal use only -- unregisters the kunit_bus. +void kunit_bus_shutdown(void); #endif //_KUNIT_DEVICE_IMPL_H diff --git a/lib/kunit/device.c b/lib/kunit/device.c index 074c6dd2e36a..644a38a1f5b1 100644 --- a/lib/kunit/device.c +++ b/lib/kunit/device.c @@ -54,6 +54,20 @@ int kunit_bus_init(void) return error; } +/* Unregister the 'kunit_bus' in case the KUnit module is unloaded. */ +void kunit_bus_shutdown(void) +{ + /* Make sure the bus exists before we unregister it. */ + if (IS_ERR_OR_NULL(kunit_bus_device)) + return; + + bus_unregister(&kunit_bus_type); + + root_device_unregister(kunit_bus_device); + + kunit_bus_device = NULL; +} + /* Release a 'fake' KUnit device. */ static void kunit_device_release(struct device *d) { diff --git a/lib/kunit/test.c b/lib/kunit/test.c index 31a5a992e646..1d1475578515 100644 --- a/lib/kunit/test.c +++ b/lib/kunit/test.c @@ -928,6 +928,9 @@ static void __exit kunit_exit(void) #ifdef CONFIG_MODULES unregister_module_notifier(&kunit_mod_nb); #endif + + kunit_bus_shutdown(); + kunit_debugfs_cleanup(); } module_exit(kunit_exit); -- 2.43.0.429.g432eaa2c6b-goog