From patchwork Thu Dec 12 00:31:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brian Norris X-Patchwork-Id: 13904546 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 5180EEAD0 for ; Thu, 12 Dec 2024 00:32:10 +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=1733963531; cv=none; b=mRfPpj+4COrwF1RD12rDEDeuaz7kkH798NknMNQvf6p380+THUM+11qbfbz83LvSV8wK3tWkPSZCTqWZ9RGCgIzaZ4hhUq6kyjlaNSmltUs18n+rpmS7EronwtHl2lWZ4Spwu/bghQ33p6Zi4Oa1+XCVZwejhoyYmqzU5c4axno= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733963531; c=relaxed/simple; bh=Kd6noYu5kKaYuzY2in9AHzWwTWDE6GDZOmHXqRdwZq8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=rmZ4foWDzP99VtJC4ljR5EIwEdVyfg+39f9MimSgGBxgiiuvdc5xc0O6kUuA3+BDOWy9ZdTXRYBuffiTzVaSRjxoCDG9EWHINTirPlWD8ddOOQ14c1uuuviwGlQTdl8pT6Wx/rVqmuRkVGMn3Lm9HGUCHQjv/ztD6iBSJj5qTx0= 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=Pp9QeeFR; 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="Pp9QeeFR" Received: by mail-pl1-f176.google.com with SMTP id d9443c01a7336-216401de828so261165ad.3 for ; Wed, 11 Dec 2024 16:32:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1733963529; x=1734568329; 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=gGGmVpvyGZhHzPnoBu+k0MVypYw0iPNz1iJuuVrkK4k=; b=Pp9QeeFRfnoMlCiiurrzdJkSvsudEVGzZvOCuEawQ413F15UbpFsEzWHAww5e5YBX5 fzCWEP/KFSJ7RgviBE8CpnHpjfbV+sw+1ub8DhqAACBAn4fWZ+CAKp7aZeRXNGOvM20T DtB+S+i+IszUzirH0wpt7FPHHPGK8XgUO9eLY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733963529; x=1734568329; 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=gGGmVpvyGZhHzPnoBu+k0MVypYw0iPNz1iJuuVrkK4k=; b=RsF2iO+sei1fpjHCnIuz7kZrBQoYZSn1gpXFHPLPMeW9KwGH235dXSDap5Ck5taFuf TueM5hixCNnGmSlyiSLNJSMKyi368tVyXdDScANKGoEXnz9tkb/tv05kjKlvVbvhbAuu bj+0u2FAmFPSRTlMVRs8aQHfh4S3KSSUO1bYAC9Ki7ZnxcgmVPG0oa2XvWI5/9linD61 TO5S3/EqLzlWst7DP/Z09FMAEol9JTyqyavQPHGqxWL+bumVPzoJYMLWLj0MbemUCWWH Rzmj++eEqzhbF/LnPwyVhVjG04X2uMq+OvSNaL7NVqTq6/SktU5PLQ6NsMP8ToKizggG xbzw== X-Forwarded-Encrypted: i=1; AJvYcCUZy0AyX+nVdcVoEjYjSv+gnaCg7b2JYRJGx/HpO613lmtRUW/mvXdzlaKCjRHkMoOw/7ELYsryyC+/rG5gRdM=@vger.kernel.org X-Gm-Message-State: AOJu0YxJ0Dz1K9irc6F8PnqJeJ8iQ3aOwHpDhBqxTr+PZW2VDtKdsSTU q5ZsJkoA7qKJLcL4o7hUZ4rj4sCfs0WcVMUpG0cGS3++mQQyE7/dmRVsRecPrQ== X-Gm-Gg: ASbGncuolEPHzTqby7wTi4az+hkqRzDpD39sf0PoZXJua9A+gW0k22sMgyiMoLGOSFA rhpYr7pByABfWiZEiEape4gdS/rZscV8r7e1EE74KIFXz6EYZFOHOGSfDTmvm+O8GYoU5O5Cchj 8H//LjI50cACONmGe2GcBHHK6HbTiSfjcOPtZTUKrtwoo/SOoaS9VMPNmYXhUEMJkGX3tqL1XrP PK1ssrH22SDPT75b0qbCmZ/hOVgqTzJc+whkfPGOgVVu4xCR0ji+tSSXwt82hvsUsGJd7+KbCVh 9vfTN4sGv1vfW9i3iFM= X-Google-Smtp-Source: AGHT+IFSuT2+ENL2AFZJMBD75mM9b3DCrYPiGx2+DNGXuCjKQhYTfFJJzw1Pi1HU4HlUFrZS1ojuOQ== X-Received: by 2002:a17:902:ce92:b0:215:e685:fa25 with SMTP id d9443c01a7336-217783b7a08mr70313815ad.20.1733963529631; Wed, 11 Dec 2024 16:32:09 -0800 (PST) Received: from localhost ([2a00:79e0:2e14:7:b1a5:9c72:5742:89e0]) by smtp.gmail.com with UTF8SMTPSA id d9443c01a7336-21680814d6bsm25853825ad.157.2024.12.11.16.32.08 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 11 Dec 2024 16:32:08 -0800 (PST) From: Brian Norris To: Greg Kroah-Hartman Cc: linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org, kunit-dev@googlegroups.com, Maxime Ripard , David Gow , Rae Moar , linux-kselftest@vger.kernel.org, "Rafael J. Wysocki" , Rob Herring , Brian Norris Subject: [PATCH v2 1/3] drivers: base: Don't match devices with NULL of_node/fwnode/etc Date: Wed, 11 Dec 2024 16:31:39 -0800 Message-ID: <20241212003201.2098123-2-briannorris@chromium.org> X-Mailer: git-send-email 2.47.0.338.g60cca15819-goog In-Reply-To: <20241212003201.2098123-1-briannorris@chromium.org> References: <20241212003201.2098123-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). Signed-off-by: Brian Norris Reviewed-by: Rob Herring (Arm) Acked-by: Rafael J. Wysocki --- 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 Thu Dec 12 00:31:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brian Norris X-Patchwork-Id: 13904547 Received: from mail-pl1-f173.google.com (mail-pl1-f173.google.com [209.85.214.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 F058C4685 for ; Thu, 12 Dec 2024 00:32:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733963533; cv=none; b=k5tEf90zHPOp9nWlig6GZh3/mWJbwpEly9fkeyKwaO7oNJFOGIyEit7pDtgQKI4vPG/erOMk0jQwnLbS27+LJHiu29TSJ4y8UbTnNBRMgKiXTg8JctafEGYXMJjj4CYks0A5wLX6XXufAJ2B1uY/7o+2QCZi+uicy2v/H+AZwpg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733963533; c=relaxed/simple; bh=D4wKzLL6P8kjio2DoNo6T3LLiJX47WeOUYHZv/B1uik=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=k9rSjSkzGbm7IGpxQ39COCGJUeh2QpuK/XqokunIE9BgXA5eACMMxXv/DrTC9FNVjtPn4yOTw9VUFkEPUKdW3qokXvsIPelPYP97SZ/SE/B9cW5+6vYrTC6uHrwjwwks/60I/pJEZ7QNU/XsQ1gXtTturIswZ2zjpBEiDJ8al8s= 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=ZQPYGCPB; arc=none smtp.client-ip=209.85.214.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="ZQPYGCPB" Received: by mail-pl1-f173.google.com with SMTP id d9443c01a7336-2166022c5caso292115ad.2 for ; Wed, 11 Dec 2024 16:32:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1733963531; x=1734568331; 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=Q8D6ygKlZnTqTfL4YWEBFZxFC5MoNr1XcjZ+M09PQhc=; b=ZQPYGCPBoxvFCCUqXwtUATpD2ZE5Fnq9gKIsBoOlyDyuGTGijm2XYpDMgoaOlejtHX G1Tv3i598PxbLDaFpIQllPCCNTjQXRFUnHn8Kj9kCaIwG0UVByNeI//mj6JnlLhRwmho Xxno8fw2kcbHhsktG7mlsoQyRFX+Fa3RCs2iY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733963531; x=1734568331; 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=Q8D6ygKlZnTqTfL4YWEBFZxFC5MoNr1XcjZ+M09PQhc=; b=NIZtON8RzD6ib8ZeL/5v1gry6IcXRXdMm2pLoTd7QNtIV7s2CYKJe30pVRGGpeLHd0 0hKlNHzwnwZ0pX3sD9UszlguHAdH3U++sD8PpzK4lQx34SYy09l34mvja5OlOYvt9bch 30UVOmx/APL4Xhxy0kZYFcfBTh2pQzlgF0WpKqEGNnV+TeiFuc73TzL3KQjdcHK6a7pp TpL+iJ+qdjIqA1fOvSoJLYdINhzia5CVlJ0CjL14dtTwWXd4b6jll/sQerwefhYPSX32 nR17Vp+oG0a1QhhobXAl++qVCxU9dvAgUrsRMNNZ7IlTYTbyLF29x8/4tTE/uI6CJ6CA 2Q3Q== X-Forwarded-Encrypted: i=1; AJvYcCVwdxZ/NYECbjQInTrlatrhE2MblwuE70mEjIpz1tcMXsOF0WekIj4PGj8p/TmxWgxSmyXPMW9qPaiCo5dUPUE=@vger.kernel.org X-Gm-Message-State: AOJu0YxsB3XZDwLbjWzhPqoqHNz83gaaDcCuhmk9453DwJMRHC7kwck2 PLvi9MxMlpz5E4msyOU85T/diHJL0L/EYiLLM787pjBW/5Ebl4iPSF1f234G4w== X-Gm-Gg: ASbGncuVyURlqCYMBXK26PQzENeYBvVxqGVLke+k0QoWHdumMH66Go0eQfgKArWJQuH ZKU1L8Osen7NOVGza/eAYZxVGYGaEIy5RqDR8bCDCxW7ZRfYqJ8hIx/rCdPYhl0b9NEeiTvy+av 4HGbPzKHO2aFHRHOC/eKnbzvGQ6yXQZCIMC+NtPWnc8Q/0POm9RKUi4Nl1pDvMGglhW00njj46r 4fUBnxxcg5o7DukW9hVIzF4PbxyvM4q2ot2ltccvWMkE8htFz6K23loc6NnOx6u1Ci5X7mKC7ue zCQmg7P1JaFrjDDkDAo= X-Google-Smtp-Source: AGHT+IHkPbKs3MqtSv9QsOis9HgYSk80Xsrurh11pKn4Z3ghlcVU8XnfyIU14vl7WdQ/uQmhi+CZqw== X-Received: by 2002:a17:902:d48c:b0:215:b9a6:5cb9 with SMTP id d9443c01a7336-2178ae4c25dmr25271915ad.5.1733963531278; Wed, 11 Dec 2024 16:32:11 -0800 (PST) Received: from localhost ([2a00:79e0:2e14:7:b1a5:9c72:5742:89e0]) by smtp.gmail.com with UTF8SMTPSA id d9443c01a7336-2163724c42bsm70938605ad.174.2024.12.11.16.32.10 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 11 Dec 2024 16:32:11 -0800 (PST) From: Brian Norris To: Greg Kroah-Hartman Cc: linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org, kunit-dev@googlegroups.com, Maxime Ripard , David Gow , Rae Moar , linux-kselftest@vger.kernel.org, "Rafael J. Wysocki" , Rob Herring , Brian Norris Subject: [PATCH v2 2/3] drivers: base: test: Enable device model tests with KUNIT_ALL_TESTS Date: Wed, 11 Dec 2024 16:31:40 -0800 Message-ID: <20241212003201.2098123-3-briannorris@chromium.org> X-Mailer: git-send-email 2.47.0.338.g60cca15819-goog In-Reply-To: <20241212003201.2098123-1-briannorris@chromium.org> References: <20241212003201.2098123-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 --- (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 Thu Dec 12 00:31:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brian Norris X-Patchwork-Id: 13904548 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 938EB2AF16 for ; Thu, 12 Dec 2024 00:32:13 +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=1733963535; cv=none; b=Ky19mKRuPL8m/WAFK4xd9Fh4fPMFxPAgR0zPqLYHpA/Jxtwy6/tMQ7iZKArKsY6RPIg3sBl/yI4bi691g33GEoTs2RizZe+8zRZzhZxiuV7E7ZfxQEHqoVfQy2Y5JXhRMs1r0rgLaQjh2yr8qQyG5Rr4xSpN4UKC9KqftZKMD/0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733963535; c=relaxed/simple; bh=y5nwWgTVBI2UXYuNENiRQFzqncmPN23qxZLRHMtG29c=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=XJnkizfZXg6XZnOPJxPn67RhdAkw1HFhRPGx85SDa2RHlpJaIrQvRyKOjDjQjgcQR+QmEZsxWSJj8R793zkOJZvRjRs+1/OBprZm+8QUqTIFOMjsqixhFEU8Xrk1cgQzcYe779S9YNxKEPuA2IKRaL9GBtWxnhLua5ulXsrLBog= 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=FCm8BLgy; 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="FCm8BLgy" Received: by mail-pl1-f176.google.com with SMTP id d9443c01a7336-216426b0865so372755ad.0 for ; Wed, 11 Dec 2024 16:32:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1733963533; x=1734568333; 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=3AVQu3QWop0H0c+IcZ6mMGnn73hEqL5BKjdosgsTiGA=; b=FCm8BLgyqZ79CS2uNCVdS/VBz04o89PGFfnlwXzBFac9Yb0nn6pKl4+cz+yP2qthbo TrVe2jYTHdVLDSH2VyerbPlA39oUCqOU35A/TkrNIOZy6/CRZTtR36vrCMqkzdFHRiSW Lo6JXXHTA0XlgC/kjG2a5d9O6t29PGw08nxKQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733963533; x=1734568333; 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=3AVQu3QWop0H0c+IcZ6mMGnn73hEqL5BKjdosgsTiGA=; b=svSa5WSF6oTyrLD4bYPbdsI8oUsXBlMsRTPM5PNUaDPEf2AS7SY3Zf85jkYe6syUBN NIoK3P6293Ngww/e3JpodU9j2mPaXfc4t1plWRXHngs8AQwbkm503jtI/9WMfU9LqGre b9/EYbDTIgFS5GJUJzV5rbitzAlUT9PW1TQVQITykbArxT2RpTOHQsh0jZmiAw/m1lVs 1mre5dk6bA3g2B2ESpQwlblDEU2UbbKxeXjgh5o3+28I5PJhsvsT65BH1/Zm6S0L0wFF Z+T7czaXzM0nxoPvhCD5HlxAf+foZsNqd67cszFYRHdUMcxRup+Mxbr39w+tZZHyRU7z Qh3w== X-Forwarded-Encrypted: i=1; AJvYcCXixNDZcfkzwaincsr44BmnVTp+WYxRRxGRnzu1Vmmkn6JqijBJQOo392gH5iNeTujtIvNUXY+TEqAKzQwcLMo=@vger.kernel.org X-Gm-Message-State: AOJu0YyFnLRRsKECq9N8b3uheRlwsjsWRZWMKniUau/FlqBcNDb7xX7s e0Q6cT7kn3oYwo3yf+zhu74teM/oFCL83AtgMoTYdaPAri2KaOrb3lZJYf2BPg== X-Gm-Gg: ASbGncvoJxko+tFobv5JCniJwBUDQ+p9YnF8pZtbbB7VD+On8/NM7MI01ICVzU9jVwa oji4526B/kMokwxdeEmc8L9GM01yuH810oEtIZ1RjkuGDBUukYR9mv6ksIeGHghNHXuQF/4YSmX nBXB4mWP+rnpdcROu2/7Opuw9iOfommhejKSjWcgpp+/8XT8M+EroGNAeZ1Q99CY0OMD7/hBIrV L3x4O/S2fORbRu03Go+OEAxfeJ5N7arPwkN7cdn52pe2ioZ1WBLZyebhM5nlTHW5bn5g2DyFHlz NBDWrt2JeK9qOWbKbtI= X-Google-Smtp-Source: AGHT+IEGLgadsxVUtkYmrldWfxFt3dO7ayUdfAi8DTpzJjhNb3S1+xd9gbNu33I+qMnncuaz+9QyRQ== X-Received: by 2002:a17:902:cecc:b0:215:a3e4:d251 with SMTP id d9443c01a7336-21778395944mr84017305ad.6.1733963532911; Wed, 11 Dec 2024 16:32:12 -0800 (PST) Received: from localhost ([2a00:79e0:2e14:7:b1a5:9c72:5742:89e0]) by smtp.gmail.com with UTF8SMTPSA id d9443c01a7336-216338fee40sm75395405ad.94.2024.12.11.16.32.12 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 11 Dec 2024 16:32:12 -0800 (PST) From: Brian Norris To: Greg Kroah-Hartman Cc: linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org, kunit-dev@googlegroups.com, Maxime Ripard , David Gow , Rae Moar , linux-kselftest@vger.kernel.org, "Rafael J. Wysocki" , Rob Herring , Brian Norris Subject: [PATCH v2 3/3] drivers: base: test: Add ...find_device_by...(... NULL) tests Date: Wed, 11 Dec 2024 16:31:41 -0800 Message-ID: <20241212003201.2098123-4-briannorris@chromium.org> X-Mailer: git-send-email 2.47.0.338.g60cca15819-goog In-Reply-To: <20241212003201.2098123-1-briannorris@chromium.org> References: <20241212003201.2098123-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"). Signed-off-by: Brian Norris Reviewed-by: Maxime Ripard --- Changes in v2: * Keep "devm" and "match" tests in separate suites drivers/base/test/platform-device-test.c | 42 +++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/drivers/base/test/platform-device-test.c b/drivers/base/test/platform-device-test.c index ea05b8785743..c8d4b0a385f2 100644 --- a/drivers/base/test/platform-device-test.c +++ b/drivers/base/test/platform-device-test.c @@ -3,6 +3,8 @@ #include #include +#include +#include #include #define DEVICE_NAME "test" @@ -217,7 +219,45 @@ 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 = platform_device_alloc(DEVICE_NAME, PLATFORM_DEVID_NONE); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, pdev); + + ret = platform_device_add(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)); + + platform_device_unregister(pdev); +} + +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 ");