From nobody Thu Nov 28 03:56:21 2024 Received: from todd.t-8ch.de (todd.t-8ch.de [159.69.126.157]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3017D14C5AE; Sat, 5 Oct 2024 10:06:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=159.69.126.157 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728122794; cv=none; b=awEWZifOAqx6rwuIY1Jqy+Hs18UhxxfcHKl5BEzhaFBW6yj6/nUUQS1u8osnu7pv8xHcwteWePd9cyO9I4pCQdY2AuKSbhFi1a2sz815r/f4c6eDWQFm8znKCh2Y/IlBTMvcb1ihXxTF89VL+VpUoAMkXCHx+ipxNusHgiesiNM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728122794; c=relaxed/simple; bh=cVeJsyW6U2wZJ6iC3eZHoUXaNynzQYlamOESFTS23GI=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=E0v9woHx/B9ic8vWgxQJkg+eQudQkkJrMv7wbUGVQafqcoW9S3iM9pZqH8X1752sRR04sdoefRA2mgUjEnGnz/Jpesf5NfrwWWGDIjXzvMfWN8gV3DyknxRdE1cdze8e4B0oiidzdlpnunafngzBrYMY3kOVj2Y2/WnQjX1o4wc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=weissschuh.net; spf=pass smtp.mailfrom=weissschuh.net; dkim=pass (1024-bit key) header.d=weissschuh.net header.i=@weissschuh.net header.b=Rj7m4jmi; arc=none smtp.client-ip=159.69.126.157 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=weissschuh.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=weissschuh.net Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=weissschuh.net header.i=@weissschuh.net header.b="Rj7m4jmi" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=weissschuh.net; s=mail; t=1728122791; bh=cVeJsyW6U2wZJ6iC3eZHoUXaNynzQYlamOESFTS23GI=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=Rj7m4jmislF/SBdurxFNvhaTC+uSfBTDDziJi43AC446/0IAvsKZYr5p/yXpKcmfF I7P6FhkoWYzA5IrwTXbHQdtwHqVJYKC/iXXIwdilx6I/NPd/kkDUlLvoFHdnfPqfr1 JfAq7Vl26caRbj6DzLKJGBqTPk4WbfWxtmSM0L04= From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Date: Sat, 05 Oct 2024 12:06:17 +0200 Subject: [PATCH 3/4] power: supply: core: mark attribute arrays as ro_after_init Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241005-power-supply-cleanups-v1-3-45303b2d0a4d@weissschuh.net> References: <20241005-power-supply-cleanups-v1-0-45303b2d0a4d@weissschuh.net> In-Reply-To: <20241005-power-supply-cleanups-v1-0-45303b2d0a4d@weissschuh.net> To: Sebastian Reichel Cc: linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1728122791; l=3387; i=linux@weissschuh.net; s=20221212; h=from:subject:message-id; bh=cVeJsyW6U2wZJ6iC3eZHoUXaNynzQYlamOESFTS23GI=; b=24viEx2PtK/jahp7sIGwnohJclF/Xq5E2PE1rJsfaqUF7sSYUZbAkq7EjMUgNQbNixmGiH+GY TiQdpwIw8NhD1t5YVN2g3tsbtM33exykL3gr3mfBiuwlv+7PUNb7kt4 X-Developer-Key: i=linux@weissschuh.net; a=ed25519; pk=KcycQgFPX2wGR5azS7RhpBqedglOZVgRPfdFSPB1LNw= The attribute arrays are only modified during the __init phase. To protect them against intentional or accidental modification, mark them as __ro_after_init. To make sure no modifications are introduced, also mark the return values of the accessors as const. Signed-off-by: Thomas Wei=C3=9Fschuh --- drivers/power/supply/power_supply.h | 2 +- drivers/power/supply/power_supply_sysfs.c | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/drivers/power/supply/power_supply.h b/drivers/power/supply/pow= er_supply.h index 1bc57615ba68fb33e5b77f720e454dbba6daa291..4c558fb3db7211a610134960292= 790ea3584b363 100644 --- a/drivers/power/supply/power_supply.h +++ b/drivers/power/supply/power_supply.h @@ -18,7 +18,7 @@ extern int power_supply_property_is_writeable(struct powe= r_supply *psy, =20 #ifdef CONFIG_SYSFS =20 -extern void power_supply_init_attrs(void); +extern void __init power_supply_init_attrs(void); extern int power_supply_uevent(const struct device *dev, struct kobj_ueven= t_env *env); extern const struct attribute_group *power_supply_attr_groups[]; =20 diff --git a/drivers/power/supply/power_supply_sysfs.c b/drivers/power/supp= ly/power_supply_sysfs.c index 16b3c5880cd8ce14cd7c697b11fcf5449b65c2d6..571de43fcca9827cf0fe3023e45= 3defbf1eaec7d 100644 --- a/drivers/power/supply/power_supply_sysfs.c +++ b/drivers/power/supply/power_supply_sysfs.c @@ -142,7 +142,7 @@ static const char * const POWER_SUPPLY_CHARGE_BEHAVIOUR= _TEXT[] =3D { [POWER_SUPPLY_CHARGE_BEHAVIOUR_FORCE_DISCHARGE] =3D "force-discharge", }; =20 -static struct power_supply_attr power_supply_attrs[] =3D { +static struct power_supply_attr power_supply_attrs[] __ro_after_init =3D { /* Properties of type `int' */ POWER_SUPPLY_ENUM_ATTR(STATUS), POWER_SUPPLY_ENUM_ATTR(CHARGE_TYPE), @@ -225,9 +225,9 @@ static struct power_supply_attr power_supply_attrs[] = =3D { #define POWER_SUPPLY_ATTR_CNT ARRAY_SIZE(power_supply_attrs) =20 static struct attribute * -__power_supply_attrs[POWER_SUPPLY_ATTR_CNT + 1]; +__power_supply_attrs[POWER_SUPPLY_ATTR_CNT + 1] __ro_after_init; =20 -static struct power_supply_attr *to_ps_attr(struct device_attribute *attr) +static const struct power_supply_attr *to_ps_attr(struct device_attribute = *attr) { return container_of(attr, struct power_supply_attr, dev_attr); } @@ -273,7 +273,7 @@ static ssize_t power_supply_show_property(struct device= *dev, char *buf) { ssize_t ret; struct power_supply *psy =3D dev_get_drvdata(dev); - struct power_supply_attr *ps_attr =3D to_ps_attr(attr); + const struct power_supply_attr *ps_attr =3D to_ps_attr(attr); enum power_supply_property psp =3D dev_attr_psp(attr); union power_supply_propval value; =20 @@ -326,7 +326,7 @@ static ssize_t power_supply_store_property(struct devic= e *dev, const char *buf, size_t count) { ssize_t ret; struct power_supply *psy =3D dev_get_drvdata(dev); - struct power_supply_attr *ps_attr =3D to_ps_attr(attr); + const struct power_supply_attr *ps_attr =3D to_ps_attr(attr); enum power_supply_property psp =3D dev_attr_psp(attr); union power_supply_propval value; =20 @@ -401,7 +401,7 @@ const struct attribute_group *power_supply_attr_groups[= ] =3D { NULL }; =20 -void power_supply_init_attrs(void) +void __init power_supply_init_attrs(void) { int i; =20 --=20 2.46.2