All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Thomas Weißschuh" <linux@weissschuh.net>
To: Heiner Kallweit <hkallweit1@gmail.com>,
	Sebastian Reichel <sre@kernel.org>,
	Hans de Goede <hdegoede@redhat.com>
Cc: "Thomas Weißschuh" <linux@weissschuh.net>,
	linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH 2/2] power: supply: validate size of power_supply_attrs at compiletime
Date: Wed,  5 Jan 2022 07:42:39 +0100	[thread overview]
Message-ID: <20220105064239.2689-2-linux@weissschuh.net> (raw)
In-Reply-To: <52cedbd4-7db2-7d81-f6c6-e6f6b7436545@gmail.com>

For each member of enum power_supply_property a matching entry in
power_supply_attrs is needed.
Add a basic test at compiletime to validate this in addition to the
existing runtime testing.

Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
---
 drivers/power/supply/power_supply_sysfs.c | 2 ++
 include/linux/power_supply.h              | 2 ++
 2 files changed, 4 insertions(+)

diff --git a/drivers/power/supply/power_supply_sysfs.c b/drivers/power/supply/power_supply_sysfs.c
index 491ffec7bf47..2565052a7a8c 100644
--- a/drivers/power/supply/power_supply_sysfs.c
+++ b/drivers/power/supply/power_supply_sysfs.c
@@ -403,6 +403,8 @@ void power_supply_init_attrs(struct device_type *dev_type)
 {
 	int i;
 
+	BUILD_BUG_ON(ARRAY_SIZE(power_supply_attrs) != __POWER_SUPPLY_PROP_CNT);
+
 	dev_type->groups = power_supply_attr_groups;
 
 	for (i = 0; i < ARRAY_SIZE(power_supply_attrs); i++) {
diff --git a/include/linux/power_supply.h b/include/linux/power_supply.h
index 71f0379c2af8..60853f26e25f 100644
--- a/include/linux/power_supply.h
+++ b/include/linux/power_supply.h
@@ -172,6 +172,8 @@ enum power_supply_property {
 	POWER_SUPPLY_PROP_MODEL_NAME,
 	POWER_SUPPLY_PROP_MANUFACTURER,
 	POWER_SUPPLY_PROP_SERIAL_NUMBER,
+
+	__POWER_SUPPLY_PROP_CNT
 };
 
 enum power_supply_type {
-- 
2.34.1


  parent reply	other threads:[~2022-01-05  6:42 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-04 23:03 Warning since "power: supply: add charge_behaviour attributes" Heiner Kallweit
2022-01-05  6:42 ` [PATCH 1/2] power: supply: fix charge_behaviour attribute initialization Thomas Weißschuh
2022-01-05 10:30   ` Hans de Goede
2022-01-05  6:42 ` Thomas Weißschuh [this message]
2022-01-05  6:49   ` [PATCH 2/2] power: supply: validate size of power_supply_attrs at compiletime Thomas Weißschuh
2022-01-05 10:28 ` Warning since "power: supply: add charge_behaviour attributes" Hans de Goede

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220105064239.2689-2-linux@weissschuh.net \
    --to=linux@weissschuh.net \
    --cc=hdegoede@redhat.com \
    --cc=hkallweit1@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=sre@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.