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: 851477 Received: from mail-pf1-f173.google.com (mail-pf1-f173.google.com [209.85.210.173]) (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 309611CF5EC for ; Mon, 16 Dec 2024 20:12:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734379921; cv=none; b=dgSwBJXZCHBusH8/OpVB3azxvZHfBHkygHF4Ae7++5QivzJ3qggSsupHZ/wO7iNKC+tHg1opdC75awC1xPqg7TotNOcu5L4hgo6x63ymyy0uSEmEhQmfZyjuwtAbMcLX7XyUe/7aGbq3AdJO+erU4yLzGtRTQMika6X1XGqRNO4= 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.173 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-f173.google.com with SMTP id d2e1a72fcca58-725dc290c00so4308816b3a.0 for ; Mon, 16 Dec 2024 12:11:59 -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=oq3HHcVc0X5f7wY5Pbc0scBXABRb0xrWVjuZPWufLJNoZIcTaBHndKgDYCyI2TWPCs 231gMsx+DnT7MHOvB/JgOt/kTU+8e7MHYyoXmmRbCCWE6UKn7HCkOCiZLoIudNFfKawj b1p4j49BcyRE4zkaoyPe+Lqu5rEuU9GoCfcDdAFLj+PhN0hYehyDbftsMiRLuPvza/SD pgiTRoHkD9vkwygkBZJbHbR9Qgt+vaRkB0ocd4O2rKHdROqNnjYhFyNGnNLTi2KYMozw 1tJvSEVaRhT7nzASs4G8Ucyk9YAN1dYdxTLN8WfqdRvfJXl+oJY670auf50m2wv7SL1W e4gg== X-Forwarded-Encrypted: i=1; AJvYcCVTtGBnfJjmC2K7Oj04px7mmDDfFfLY4oDfHMdA7c/0f517cZsTcg/N43j8xk734YGvVIA3fJNaDwh1@vger.kernel.org X-Gm-Message-State: AOJu0YwyAy8IAWM/V8wv5liUH/4XQH8eMgOcvge/UxkcVEOVECjJVqX3 icChxfRxr7wXPf83An+lg4ayxY4HLmuQHdqJwqA667eCeqjNXMNP9tYUNdAfaA== X-Gm-Gg: ASbGnctQ8aiBKy9sfWWkvbbmLnyYXAgsyp/z4YMPfKoJ+sQhDL7viSGpyHTp2DwXt+j kn++lYNwZEorh8si4tj72dezz6YFB5DfKO22OrXS50q6gVMfAVFMKcI1FL/z40dHfLLiIbT/V1v mk8gxxM5e3JxJIq0NSwSztrte8Rn/2Oa7f7SScH6YQf8nMNTkr87Lj8Kt7O0fY77sBxnn29saVJ jaEgIYokGmozpisGON23XH76VNr+/7rB8RZx5kPBpsN+BbzF12+oqfsGbwEvhzSezhYuesCuJOB KUpTApZWRXr2AqbKPA== 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-acpi@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 --- 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: 851262 Received: from mail-pl1-f171.google.com (mail-pl1-f171.google.com [209.85.214.171]) (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 DAA731D434F for ; Mon, 16 Dec 2024 20:12:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734379923; cv=none; b=Y7yecPaJ3PYQX7EJsTy7Exwod89VQ4FG58vtdMgLlrL5St1IVt9gdh8i/cZKiEWDQWjV3kangx7LUXyYAZ44fIQYCkJUD/quaOw8PLhiXoSwDvsBkckXdrC0bamWqzZrgFsCeXQaNj20YX1csXluQ0zf6sGjjf7Ira4qUfPg7b4= 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.171 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-f171.google.com with SMTP id d9443c01a7336-216426b0865so39560275ad.0 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=hVx3vDirQkGPMJAhCz6dVXh8wuEHeWihBPys1xPS9EeNTCupYCdXZ/1Y8pluLBK+ig 3QUDg7HtoodPvKh7oOylamLlShs78PlXR9aXd4xPEOrrBxMr4ih00YmpUO8NZEjjePO6 BVXcnRnLJrksFdN93fs27LzJ2z0M+xIqI8+FKfXQ1sFfVxUdRJ0z6aB3b2ZYe7OIS15J rJwY55FeUVsUfgsD1H43itVdFRlSrh/z9PkPN0evDOtiNEtg7KskuP20eQeStQrwSWNT V40MpRU0KmARIuocCQkwtS6xpFClXKDfMHQHj6bIxTnwbdWy+qtuIcoHxC8jEBi5qywm cRDQ== X-Forwarded-Encrypted: i=1; AJvYcCWE77XGHpbBhLhuAIHG8Ij3ZbxjQFbw8XiLPUsJMSmrpGaSXtmzfDvnBJZWMAahbJMvq2dbddrsR/Mi@vger.kernel.org X-Gm-Message-State: AOJu0YyvVBmkkEtePv2kXeTQ/IY4MxfqyaJ+WotYOusa3qXC4eYjI/pT wlhyBE5eK3UZkUCpX6DFN412k6Avmsom6to47hgfBhMY7rmc6jk0uDd6aWG+RQ== X-Gm-Gg: ASbGncu5WPBExh1aJek03Ha1R3S/72UbS+eub8GsA0W4aZS3oX/K7nSAkBWeVEBgF+e ssLibbgEkF8WSE41a+4SEKs0iazwpD8dg6RAC/sQExx5M8Rwx1mO2bEH/rRWRVUDY1Ze/woOMcn flMpeqZ3H67NFVB2TZNz/n8qlaUsj/Eju8dp5PH7xdNWXJOjqqP4E4L0kjfthOl8hU5sTiIY72a VLYjRUgft+h7MzSN4TwHELsae23oz5Zt/gj9aHzIgoJg7R6G4BJGFofRwkrJXQokLanbvyTcgn7 eE1RZDg+0mf+Xo0BvA== 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-acpi@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 --- (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: 851476 Received: from mail-pj1-f53.google.com (mail-pj1-f53.google.com [209.85.216.53]) (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 A010A1D5145 for ; Mon, 16 Dec 2024 20:12:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734379925; cv=none; b=sdr1fEjzrZrXEaCgd8+Yt2f7tlnSLjWjIFyiuT+TqsO71XF61a5d+FcQ+2kt6Ui87oHS8t2enb662qIV8tMWkhoRnFu9XNdzfHT0lHEnoEPwZqANut4fqOOqI4FI1CYixaJTxS7/Sn0YEcfhGQhAwM9HYzgv3FM0sYxMQmxX1aA= 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.216.53 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-pj1-f53.google.com with SMTP id 98e67ed59e1d1-2ef72924e53so4066753a91.3 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=TFP+y+qnh08M5uG0ElqF49ftIltJ8y25hlFh1/AA7xEWtQvL+IpjpWwiLpJ6Db65n+ xDHyUSufVbUHm6OpStXIG+mtuuL+RiP7OUVtI1EATXCek4z+kkrSR9Sw2nzPUhU5817O UKXg3wOhxBK4HCyLQ0Ha388j+JiaiOUqbT1qk2wWGwdHe8nAoXfAI53t3DQQCJaYGz4B K3f/vDPZgHB2BYzUkdJZ3qVIQBpzVkln6VHjQNtinzc0aN1BxjAnYDoN4itwuPSQHkUc WivpAI6GnpXw58K90yTat6sYcMOihwWhr5uzUwOQsD17pcmI5taIN9EYGIZTNnXh5MuJ tDTw== X-Forwarded-Encrypted: i=1; AJvYcCXjLhoTGYtZ6n72aAOuDHHnCk9BUev1PqSwJuIU/rlj08ZAMkNu+f3Q6FOSY7QlT8Yk8XC9S/n1Q/Et@vger.kernel.org X-Gm-Message-State: AOJu0YwzbruT5zsCIdl76m2XL4Ma9RaJd+09VUC6qHiy5mEcROzYUu8x YQaHRpfYUIzCDfmplQcK70w8hhhbzgfmRIVtBKg991rJwBBPufs8wlryuq6R9A== X-Gm-Gg: ASbGncs3LjwOFGRGajb0HxJ5/8mR3VTiKp2j9FQe5F38gfU+4LXDBARNMWR+f1cR8it VCME5zQnDlDyfqmNlU8vfaIpZu/XvDcgvasPfpBddyJWeHhpys7lBc1hyGAUKyC1X9kITVSJtna mt0gQ+bycalrpLtMKVtv4IDL+ljPQCZwW4wcx0X1gs1dhfN/Ft6fmN+NtHvgYVufnHqpO3fb5xi JXyqjHvm80K/ZdsfWuoP9Q9ye6INQOIOYQea7AyLykq1kVm+w9qEmTjBKtTFdRJcFDwr3yPKFsf u2WHWIeUbod4PEzRxg== 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-acpi@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 --- 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 ");