From patchwork Mon Dec 16 20:11:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brian Norris X-Patchwork-Id: 13910282 Received: from mail-pf1-f179.google.com (mail-pf1-f179.google.com [209.85.210.179]) (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 4E4B01CDA15 for ; Mon, 16 Dec 2024 20:12:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.179 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734379921; cv=none; b=fn0fbZoByfWJv8X7Rky/OlOcoe+apDD0p3nL+R0qR/PIdnqAlC4bNTrrSlSguQ/FnrOXpNJ3bdNjnJNC0WYHaWzembDCEKjSS/KKIwFztNiw/RXKc0CLFE/nFRCX7F76sYHCBaw1oreicM4RdDTEs0D5ju5VFDQqLJLAh/Vm3jc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734379921; c=relaxed/simple; bh=7jxU4hpAwSWmevfX99YkDoTD1JGxKAVZgzPD8jgn35M=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=XCHt8Jbl8phvdbYMLVkf9iWvFQCbrS8rWe7Sbm4b2kjYQsY+nLaqPHgBvQXAWs7VdfNfIqzqL+ieSkRrmA/hWGS5BVJo1n3wfNZd/xP4e0u5jrmWE/1wouY84613e4P+EQobyUWub5kWq3PfoUnP/HffBxq1thEVUWKwxNpvLro= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org; spf=pass smtp.mailfrom=chromium.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b=CNdanyNU; arc=none smtp.client-ip=209.85.210.179 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chromium.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="CNdanyNU" Received: by mail-pf1-f179.google.com with SMTP id d2e1a72fcca58-725e71a11f7so4091047b3a.1 for ; Mon, 16 Dec 2024 12:12:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1734379919; x=1734984719; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Rqa++bQfJwX3ua/s3cRo3Ckug/2w2jf2s5usPRs7cJ8=; b=CNdanyNUq4OPpiruLbQnSyqtd0ycqSKEQxMIWRqYCAScBtfZEnK6Tjy9U3l7hErlNH tIgU500AGccqO4DY3FmhY6Tvk9j6RTNs9C+AJE/ufTzIjYMCqvZ0HzdpaojP2FrhRImq 4ZJu5yKy6pyFMHRA//y+PJflXxBL4BCEaczSo= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734379919; x=1734984719; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Rqa++bQfJwX3ua/s3cRo3Ckug/2w2jf2s5usPRs7cJ8=; b=otvMQrX4tl+/tUlV9UFIrTycaypb0do1wkJlDDcP4m6aN3fB5e3upHvFeHS124Ymbh NMPYIJf3ZpJE5uqGFFjxvmN6Ym7HlHAs+HAgAaZ1tMUvX6Z5BjH87WI1ZN2gaFXgesSR GP6YfRumX8jeOQ0R2lkbaW0tT1WCrH2Fmc6nxL13KpV3lKZ9yQUBVrQMVTAn2Zj9TD95 YxU8gWvGNB6NdJmBeMktOUOtvMztHH7cvzv1Pc/M6Nxj7rgftXhOaETKgZlhDvhWQLIR 9moHLlZvJ8EuDHN8rbMg+w5CiI7n2mY9U712o/CiodHSZ5Vokbcrl7FDZmL2eUrA985m YR+Q== X-Forwarded-Encrypted: i=1; AJvYcCUMlna6Nh5Ja/eHf6eK62lM0mMdbzB2AhIqMPsQwZJxrdhCEQxEamNP6H4tvm3x8u3DO7TiHVe7zqqzw4nxOPU=@vger.kernel.org X-Gm-Message-State: AOJu0YyFokqmx+a4L4HDLRoaP6mgMn0jk50begosdRrEN0I7g47W+EEk BkJOjBJYRA1foXnxnM5OuQ/XXlOHugM4pbzYvL9mAJl+2H983l259/wdnd48pg== X-Gm-Gg: ASbGncuaypREvf9H3Xh5G/Z8cSPlSP9VS4lkG9lZPpbkuBtb9Pb0bPRgMMbrCc7SUXf ZcEu2GdjdDdO8xgb4/gdaP6FnJFfJUjN7soMMEOCq3kvMD3LGV0yKNC0zte2wROgFoc1EwkWXn+ v+FXApu6XFfbrNPfhF3LQBCD6KIehfjB/sTQp5vJREAqFISJSNuwuLkFHNi0lIFNRbmYqMVGK7q URMaty928Z23IlXJD21032XXsBIkbScHqNBveZukQMeylC6xRuV2JTlcKG1lYcEYshD7wELWeeJ xQwweqE6roIUUl7BZw== X-Google-Smtp-Source: AGHT+IFgqfe+kqsUtZy9+xGWMGhOgzZuAgj5lfe6mAr4/ZjzImfvHLnClnHam5X0h2CYqu1MJB3xkw== X-Received: by 2002:a17:90b:51cf:b0:2ee:c30f:33c9 with SMTP id 98e67ed59e1d1-2f2d883bf1emr990096a91.14.1734379919583; Mon, 16 Dec 2024 12:11:59 -0800 (PST) Received: from localhost ([2a00:79e0:2e14:7:953:5b91:a52c:e817]) by smtp.gmail.com with UTF8SMTPSA id 98e67ed59e1d1-2f142d90bcdsm8423943a91.5.2024.12.16.12.11.58 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 16 Dec 2024 12:11:59 -0800 (PST) From: Brian Norris To: Greg Kroah-Hartman Cc: Maxime Ripard , linux-acpi@vger.kernel.org, Rae Moar , Rob Herring , David Gow , linux-kselftest@vger.kernel.org, "Rafael J. Wysocki" , kunit-dev@googlegroups.com, linux-kernel@vger.kernel.org, Brian Norris , "Rafael J. Wysocki" Subject: [PATCH v3 1/3] drivers: base: Don't match devices with NULL of_node/fwnode/etc Date: Mon, 16 Dec 2024 12:11:42 -0800 Message-ID: <20241216201148.535115-2-briannorris@chromium.org> X-Mailer: git-send-email 2.47.1.613.gc27f4b7a9f-goog In-Reply-To: <20241216201148.535115-1-briannorris@chromium.org> References: <20241216201148.535115-1-briannorris@chromium.org> Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 of_find_device_by_node(), bus_find_device_by_of_node(), bus_find_device_by_fwnode(), ..., all produce arbitrary results when provided with a NULL of_node, fwnode, ACPI handle, etc. This is counterintuitive, and the source of a few bugs, such as the one fixed by commit 5c8418cf4025 ("PCI/pwrctrl: Unregister platform device only if one actually exists"). It's hard to imagine a good reason that these device_match_*() APIs should return 'true' for a NULL argument. Augment these to return 0 (false). Reviewed-by: Rob Herring (Arm) Acked-by: Rafael J. Wysocki Signed-off-by: Brian Norris Acked-by: David Gow Acked-by: Shuah Khan --- Changes in v3: * Add Rafael's Acked-by Changes in v2: * Add Rob's Reviewed-by drivers/base/core.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/base/core.c b/drivers/base/core.c index 94865c9d8adc..2b7b13fc36d7 100644 --- a/drivers/base/core.c +++ b/drivers/base/core.c @@ -5246,13 +5246,13 @@ EXPORT_SYMBOL_GPL(device_match_name); int device_match_of_node(struct device *dev, const void *np) { - return dev->of_node == np; + return np && dev->of_node == np; } EXPORT_SYMBOL_GPL(device_match_of_node); int device_match_fwnode(struct device *dev, const void *fwnode) { - return dev_fwnode(dev) == fwnode; + return fwnode && dev_fwnode(dev) == fwnode; } EXPORT_SYMBOL_GPL(device_match_fwnode); @@ -5264,13 +5264,13 @@ EXPORT_SYMBOL_GPL(device_match_devt); int device_match_acpi_dev(struct device *dev, const void *adev) { - return ACPI_COMPANION(dev) == adev; + return adev && ACPI_COMPANION(dev) == adev; } EXPORT_SYMBOL(device_match_acpi_dev); int device_match_acpi_handle(struct device *dev, const void *handle) { - return ACPI_HANDLE(dev) == handle; + return handle && ACPI_HANDLE(dev) == handle; } EXPORT_SYMBOL(device_match_acpi_handle); From patchwork Mon Dec 16 20:11:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brian Norris X-Patchwork-Id: 13910283 Received: from mail-pl1-f176.google.com (mail-pl1-f176.google.com [209.85.214.176]) (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 0B5161CDA15 for ; Mon, 16 Dec 2024 20:12:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.176 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734379923; cv=none; b=Qn2RsyvqIZ2S+JByu7d93dhyMo7CEmgnqI54Mp3jzOSHKvuDXg49ec0q49/wtSM9mui2O4C6iXvKAXULPFJqFw5a+Krvn/goH4vsIu3VfS/iADXN6ZhuiDV6a5HlOc1bGEBLoJGzCsEQY9leTN7LXS7nCYu3StLyyyYYCbnDt8I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734379923; c=relaxed/simple; bh=wcShxfPbnClrISO1dAhdVjYKxC3gZhQzGp9ty+s6tng=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=heF5oXSV8ad15AsicuSN1cfsJem07HD4ZC9CNOYHFG/GxtPz9Kee83Zj6tx6KlSMQ9dstWx7D79p97cDfGjaUd8w3TdlzpYj8ukJ8e+SCfUPlHmzy8XJCeQRZW3NYCt+dfsC4nytIHDqo1LAQWO3Ae5slhgj0sWUsLvXDmpq18U= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org; spf=pass smtp.mailfrom=chromium.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b=CyxHrd6Y; arc=none smtp.client-ip=209.85.214.176 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chromium.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="CyxHrd6Y" Received: by mail-pl1-f176.google.com with SMTP id d9443c01a7336-2161eb95317so41742135ad.1 for ; Mon, 16 Dec 2024 12:12:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1734379921; x=1734984721; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=fBk1B/iGfmqWsVYAcS6S50yqQBfz2Y6wZFszhj2EhmQ=; b=CyxHrd6YQF7GWWJ2k+SbX9xh/haSR7y2Ih/2Mi4+Xv/ldkmYPGVqY0UUGK0Qys90lB HRhKFYcYEKnMdMV1aCFGCj2x0xOZwJb6vYkTy95JQo/ArvScjPor5GVmQEyTaoR8pgCn DgRWUHzdCeEptJR2TRwOt6EzatwUofbxcxqyQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734379921; x=1734984721; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=fBk1B/iGfmqWsVYAcS6S50yqQBfz2Y6wZFszhj2EhmQ=; b=Z1/DIUcwrMUnEobMzIPYAkL0OAj0eglTOl8L9YwdRp8yZOZabMlMxQNn9R4qHETVVc 4BLtx0LnnmDcfv2uLuPmdaCoGEnUo9TVzTB5MD9mdUehBH+pop595N+naN5cnyXVDTAS +DzMXM8Tgz76ARMEByeAzkcKE/d4mMkMgqm8Q1jJCAX9gO9Ab2p4wZ757MGdoG2sbm4B k81+DNkS6A+e8LCAShIEOTVu7O+ot/MPcD7UlGAuvMlOPrfqgEQcOLlsGMZma6a1z61E oVlClqxQ5L4arnPUBd7RfDX0DSh3IUIXQQgWLzKqZpAoMF5hg63oFHEJmqOShXGCNSvE dxjw== X-Forwarded-Encrypted: i=1; AJvYcCVTXZw23Ta8FKElebX95siVP62r/SFfSGKWxeVmlFeNEt4L6n+pQRUb1G1sq1aOrvo4j3l/XGmcTsni/7mFV54=@vger.kernel.org X-Gm-Message-State: AOJu0Yyh4dRgSJaO/FAqmB353guPwkijdm9RukiXT2HW3IRz1ge7i4mr NJ+Afp2V1HlddutHR9eocaw3v81RPrp1x1SLxHn6etlZDGFtS8HyDlHmvAeOdQ== X-Gm-Gg: ASbGncvqU/GlhcPQAGWjfkmeLZL7hjgMmjJ8I7TkDR5RvdqYt2PLEb2Lvy7lqtceGGj OUA7TTy29yaYLb7QJwn9+Papnl+UidhZJ4Px0PfZGNIIhVxoyo2MTWpQK8indM+Jdhirw0aVnER DqZKhS1v+SozSYu4YBlImdXanK3tPJctptoT4l6HgUpS7AnM3pdlwino/esJmQFjv5S5zyYpsgS DoHZkv8Q40lp6ACeYNitvTUTpcmX66fg6dCqyAyjcZhpr+mPXgpgHb1sqrtmy3AEmIWa8slm9TB Q4yBTVHoc5+24QAIxA== X-Google-Smtp-Source: AGHT+IF2iv9Je95U9OGbHT2oN5GIgDqe2UtAMFx/DSAMFSH7IN0Tter2gRXLrFhHCS1ZV+etVrE7DQ== X-Received: by 2002:a17:903:3256:b0:215:7faa:ece2 with SMTP id d9443c01a7336-21892a4177emr159121845ad.35.1734379921239; Mon, 16 Dec 2024 12:12:01 -0800 (PST) Received: from localhost ([2a00:79e0:2e14:7:953:5b91:a52c:e817]) by smtp.gmail.com with UTF8SMTPSA id d9443c01a7336-218a1db5883sm46591995ad.41.2024.12.16.12.12.00 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 16 Dec 2024 12:12:00 -0800 (PST) From: Brian Norris To: Greg Kroah-Hartman Cc: Maxime Ripard , linux-acpi@vger.kernel.org, Rae Moar , Rob Herring , David Gow , linux-kselftest@vger.kernel.org, "Rafael J. Wysocki" , kunit-dev@googlegroups.com, linux-kernel@vger.kernel.org, Brian Norris Subject: [PATCH v3 2/3] drivers: base: test: Enable device model tests with KUNIT_ALL_TESTS Date: Mon, 16 Dec 2024 12:11:43 -0800 Message-ID: <20241216201148.535115-3-briannorris@chromium.org> X-Mailer: git-send-email 2.47.1.613.gc27f4b7a9f-goog In-Reply-To: <20241216201148.535115-1-briannorris@chromium.org> References: <20241216201148.535115-1-briannorris@chromium.org> Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Per commit bebe94b53eb7 ("drivers: base: default KUNIT_* fragments to KUNIT_ALL_TESTS"), it seems like we should default to KUNIT_ALL_TESTS. This enables these platform_device tests for common configurations, such as with: ./tools/testing/kunit/kunit.py run Signed-off-by: Brian Norris Reviewed-by: Maxime Ripard Reviewed-by: David Gow --- (no changes since v1) drivers/base/test/Kconfig | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/base/test/Kconfig b/drivers/base/test/Kconfig index 5c7fac80611c..2756870615cc 100644 --- a/drivers/base/test/Kconfig +++ b/drivers/base/test/Kconfig @@ -12,6 +12,7 @@ config TEST_ASYNC_DRIVER_PROBE config DM_KUNIT_TEST tristate "KUnit Tests for the device model" if !KUNIT_ALL_TESTS depends on KUNIT + default KUNIT_ALL_TESTS config DRIVER_PE_KUNIT_TEST tristate "KUnit Tests for property entry API" if !KUNIT_ALL_TESTS From patchwork Mon Dec 16 20:11:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brian Norris X-Patchwork-Id: 13910284 Received: from mail-pg1-f181.google.com (mail-pg1-f181.google.com [209.85.215.181]) (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 9AC401D5143 for ; Mon, 16 Dec 2024 20:12:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.181 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734379925; cv=none; b=Kkee2721QA1iZbPP4TJACL0P0/pCMnAdlzzZVJXS43cZdkHFNBNIx81TzQhCo4AH5yKrEURbmVKVPsozGA1lF9J1xESVwRyuy97DBES8p+T9SqHPeI+KlE3OAubCv6be2rDpLEAoxIu0lieWjVchNSODTQgYgQNqOPSwxWalGrQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734379925; c=relaxed/simple; bh=H6OpmDmtDpO2Zw9oPoveIwfU5S4mQl0QvewtjG8lnI8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Nc4fRtVcwkKd62aZ3T4zqDmWdUfdYY9TtWvYMq6Iv7QAKb/vqgALjItYeUP0qWH6vKmcn3/sE88TWY4haeTUfQoPX+7hK+PhqTEwbLtUbKcxF4o+0GZNjANN0Fc22/YR/q2LmC3QS22icR+sxN1qKTBv4ssa2JuMgzWBzSegAuE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org; spf=pass smtp.mailfrom=chromium.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b=idTMj13b; arc=none smtp.client-ip=209.85.215.181 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chromium.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="idTMj13b" Received: by mail-pg1-f181.google.com with SMTP id 41be03b00d2f7-7fd526d4d9eso3512611a12.2 for ; Mon, 16 Dec 2024 12:12:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1734379923; x=1734984723; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=djvMV74okcAY/0lAlFHYz0uZLVdKOBaTEOPTBRi9sN4=; b=idTMj13bH3WLlPjKnPfPxQy6icNRx5Eo3xCf847jUnA8aJR7pZcF3bHgB7K9qR2o09 3vmWy6pB9uazkqDyc/hromm4TA8eu9D3LlTPfjlTeO7GhjHNABLwnLtMZgKpGIupCQOp nBwkiWGsGGJHuB25kMdKdDK/Vr4yvvJ+VLXHE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734379923; x=1734984723; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=djvMV74okcAY/0lAlFHYz0uZLVdKOBaTEOPTBRi9sN4=; b=fi8Cabl8TWOIOTeKr4F8fB5XwY3VUOwNTT4HMbkLYexI4Ww0A/zZI8OtIdPhysPVZ0 ZP8QgnKfvCsErzKSMLXUXZ9XVC1+b2YuIaRrttcbEuxju/04Lj1bJXTHMwwgWjA7YJtm OpBHRcsgXWD/8EEffgd5kI0LtkScGN42QTCIOUn/t36cqAaGR8Aq19SMuC7vQkg6zUEc hpL8vw7cIJLdpKjVwhs2TW42Gb6guajN6zxjIEB34sgwgbklv5IxQxWjL9C0FiSYCAa6 1X/P7DMz4/Io7yhCFrH1LegVqI4R0qm153ns3mlh2EMV6yLhIv6cG4Vz0WyqZRQfCcQF NVPQ== X-Forwarded-Encrypted: i=1; AJvYcCU6HMw3iO+UJlLrX1nP+5AQFnDMteOfjYQ2MDvx5CqdQkQiKV9noIfC3HBWyaCDhKpn7n8tKLXZxHOs6IzMcco=@vger.kernel.org X-Gm-Message-State: AOJu0YzbyLHrlrPMWY7fzTi2uehVxpOx0BavJrEqsZJrh7GfXZKaG1aT e95ryNAFBNafnIehW4pBHj85KWM+qqpYJeeqQNsjpyKN2AfmQwxg6NBZr9XEHsmYIs0cKHq9RRk = X-Gm-Gg: ASbGncvqWKBFygAYtYsd/5/w2zspuw6Xwmzt+APh5d8FrohfgHmipfplUTVfeBSDKIu ZEZ66D0h7wc6sSD4k7CjhhyseFERbUaH6WRwTrHrVcAORBqeFbXYmmyRzv94xb1t0yr5cnEh0FE f0bbBRTuU39oDE1E3mKCTjQqrv2qn0XHERUTThTupVY+E1bAsGPNYYbAhx9KfnkGmWngPT9xN+S WPMsAaWA84+YuPx1mOTYg1NbaDXBlFodHtYJP7MSdkNxi0P3DhD/+eNZlTBGcKbNyAk/C+E5zP0 sSUiPROYukecqfcl/Q== X-Google-Smtp-Source: AGHT+IEis0SU953jTVyxT2H0yo03Me4jIuEsbijattQtH7vbZS2FTiO7qBvoO1t0qS6vmyUZ86ypdQ== X-Received: by 2002:a17:90b:180b:b0:2ee:dcf6:1c8f with SMTP id 98e67ed59e1d1-2f28fb71a7emr22546306a91.16.1734379923047; Mon, 16 Dec 2024 12:12:03 -0800 (PST) Received: from localhost ([2a00:79e0:2e14:7:953:5b91:a52c:e817]) by smtp.gmail.com with UTF8SMTPSA id 98e67ed59e1d1-2f2a1e7e07bsm5122503a91.1.2024.12.16.12.12.02 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 16 Dec 2024 12:12:02 -0800 (PST) From: Brian Norris To: Greg Kroah-Hartman Cc: Maxime Ripard , linux-acpi@vger.kernel.org, Rae Moar , Rob Herring , David Gow , linux-kselftest@vger.kernel.org, "Rafael J. Wysocki" , kunit-dev@googlegroups.com, linux-kernel@vger.kernel.org, Brian Norris Subject: [PATCH v3 3/3] drivers: base: test: Add ...find_device_by...(... NULL) tests Date: Mon, 16 Dec 2024 12:11:44 -0800 Message-ID: <20241216201148.535115-4-briannorris@chromium.org> X-Mailer: git-send-email 2.47.1.613.gc27f4b7a9f-goog In-Reply-To: <20241216201148.535115-1-briannorris@chromium.org> References: <20241216201148.535115-1-briannorris@chromium.org> Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 We recently updated these device_match*() (and therefore, various *find_device_by*()) functions to return a consistent 'false' value when trying to match a NULL handle. Add tests for this. This provides regression-testing coverage for the sorts of bugs that underly commit 5c8418cf4025 ("PCI/pwrctrl: Unregister platform device only if one actually exists"). Reviewed-by: Maxime Ripard Signed-off-by: Brian Norris Reviewed-by: David Gow Acked-by: Shuah Khan --- Changes in v3: * Fix potential leak in test error case * Add Maxime's Reviewed-by Changes in v2: * Keep "devm" and "match" tests in separate suites drivers/base/test/platform-device-test.c | 41 +++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/drivers/base/test/platform-device-test.c b/drivers/base/test/platform-device-test.c index ea05b8785743..6355a2231b74 100644 --- a/drivers/base/test/platform-device-test.c +++ b/drivers/base/test/platform-device-test.c @@ -1,8 +1,11 @@ // SPDX-License-Identifier: GPL-2.0 +#include #include #include +#include +#include #include #define DEVICE_NAME "test" @@ -217,7 +220,43 @@ static struct kunit_suite platform_device_devm_test_suite = { .test_cases = platform_device_devm_tests, }; -kunit_test_suite(platform_device_devm_test_suite); +static void platform_device_find_by_null_test(struct kunit *test) +{ + struct platform_device *pdev; + int ret; + + pdev = kunit_platform_device_alloc(test, DEVICE_NAME, PLATFORM_DEVID_NONE); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, pdev); + + ret = kunit_platform_device_add(test, pdev); + KUNIT_ASSERT_EQ(test, ret, 0); + + KUNIT_EXPECT_PTR_EQ(test, of_find_device_by_node(NULL), NULL); + + KUNIT_EXPECT_PTR_EQ(test, bus_find_device_by_of_node(&platform_bus_type, NULL), NULL); + KUNIT_EXPECT_PTR_EQ(test, bus_find_device_by_fwnode(&platform_bus_type, NULL), NULL); + KUNIT_EXPECT_PTR_EQ(test, bus_find_device_by_acpi_dev(&platform_bus_type, NULL), NULL); + + KUNIT_EXPECT_FALSE(test, device_match_of_node(&pdev->dev, NULL)); + KUNIT_EXPECT_FALSE(test, device_match_fwnode(&pdev->dev, NULL)); + KUNIT_EXPECT_FALSE(test, device_match_acpi_dev(&pdev->dev, NULL)); + KUNIT_EXPECT_FALSE(test, device_match_acpi_handle(&pdev->dev, NULL)); +} + +static struct kunit_case platform_device_match_tests[] = { + KUNIT_CASE(platform_device_find_by_null_test), + {} +}; + +static struct kunit_suite platform_device_match_test_suite = { + .name = "platform-device-match", + .test_cases = platform_device_match_tests, +}; + +kunit_test_suites( + &platform_device_devm_test_suite, + &platform_device_match_test_suite, +); MODULE_DESCRIPTION("Test module for platform devices"); MODULE_AUTHOR("Maxime Ripard ");