From nobody Mon Apr 6 09:10:53 2026 Received: from mail-yx1-f43.google.com (mail-yx1-f43.google.com [74.125.224.43]) (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 7CE3728469F for ; Fri, 20 Mar 2026 04:08:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.224.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773979723; cv=none; b=jW0Nn6HLNNadvbVUP2KrzIcv0KlfqhMYVmOLRSYEgjB3cdPBKwNSRqgHImFavH6hfncghzvz/FQn2gJ6Apoo3kz1uGiez7WJHq2yKRVpWjIUlXGtBRWaql7ZyM1uRK6tkrE4QKe+AxlcZRjk+q7tFV+6IXpUkWKbDaltVegev08= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773979723; c=relaxed/simple; bh=Hs5JCVi/mDCoUp8T9yD6sHiPNpI9OAcvAkx6z54p0S8=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=QTXHKKlumTIM74eiSpJiUJnTjcb6PG7cv/uc4mFq8A4okj5lbtH8PtCR579c8prh0+OAHzCMA5/FFY7pXZNgJhhDEZSwgDMrY38C/NznlFvNKZi3ZFIfprxZaT1cnNZcI8n7p3/0sa6FBeDgaturbCcQo0HJXghUCWx17EuoHxI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=FoIh34cn; arc=none smtp.client-ip=74.125.224.43 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="FoIh34cn" Received: by mail-yx1-f43.google.com with SMTP id 956f58d0204a3-64c31ca77b4so202676d50.2 for ; Thu, 19 Mar 2026 21:08:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1773979720; x=1774584520; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=9qXYjAYEG/7TdZTZTuXrafJ6evX5BXEzOr2dZP97xrw=; b=FoIh34cn5A4QYrPFj6riiJSMAqmdTsurN9HdQ3GjBIBzp0VG6BUAFckjIPSiahe9Eq zKnRVFlC0a7B88M7wdXqELpWk96HgenxFHxlCOQLf7082qllyyyxrTiAGQXFgk0fKZMi A2rKbZW/5DbGM7Cf24naDkquQajB0yjf202sKUilHm+whhp5JDPvvkY/GHmagleAOa9c HnBFKiMhCE5oUsrGBkHux0OqFKvp5WLGkci/Yk1VKCeeDswTTJPCKTW5VXglz8/FMAwI 86yuTMJBWnmpdroQftitfZM6XNpMbORGLDeMBQU+aTVHvvZNEvsNk4yCSJYKKSW8eO/k iubA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1773979720; x=1774584520; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=9qXYjAYEG/7TdZTZTuXrafJ6evX5BXEzOr2dZP97xrw=; b=TOg0nV5j6+TAUhXyVqwxkqNct7xMbw7nf3RfPstwa+6VdWdKPrBnBibjxQJW8kEi+G a89SW2CKJ7+uix9JG5SzjSpL2lm2AGqES2ygPNiRGX0Xo1ioZl3kmbrSgWgi+4j4tRv2 IoGIVUWBABKEWX0mZCq40bxoVLDRTUVC96p98wPGgl7yXMzxPH6xAmyJbyqRkZipQokN ZtxeYIAgGMzxO4dE+Yc7zXWw09CSPfUcKspuJFwv1GcnNaEl+4q3GeYdO1fG/9D68Ubf 3ovxqsk7XIirwsmjF+U+GsYGsIcrHgdLbOfL9vgExRB2wKaib5Wdm4YOGfmt67tDgygF WGew== X-Forwarded-Encrypted: i=1; AJvYcCWcb+433e+C0SMOb5SvGh3vnjTe5vJKh2NcTiq6ORRgw0nYepgPtWawlthiFhnMzAlg7nXgY+lKQyT2MYQ=@vger.kernel.org X-Gm-Message-State: AOJu0Yw/ptw2jw+LuCC7nvrjUIBo1MNQFV0fngrUxLQ18V6wrABJ08Qa bNtjUnWT6LXx/Pwwg1LLH9MIhIBD1ZT70D01l4gwPquXaDKbX8+E+jKMlgjtOMU9 X-Gm-Gg: ATEYQzx1XrjjqBGlN6/v/s/fzqmP3ayX82pKifPaGrOjXSnEWHg1mpZQc6PN/RoMlei hUKsYn1qF8vxq1T/lNUqBGpMg23O+GxVOI9inqD5Di1hJfO45L+2W4XzZx5/1/FC9UdIq42Khb7 BYhf8D5VmDMrzPihksCUbOo0fhkW7vl5jWzNGaoITYa2h0HLg4j8HGOxuKh3dJHEoVMWqLZt+LS BqUjXG1J51jp73yJxBBRmapkkpRcVyF++mZ3B/hlNoPtvZcF9rcJf3Dou9cSPEZ3GiGxXtcHdqb zqyg66rc223B2zCbBy1UBY2Ah6ExT8C18k8yyAgnmnIKTv8+6EYjqN60N3USDC+I9L6cMXNDjkZ j06rF+rgH4Dd3MxU001oEfPs6lBd/jmxRIpi1OY7KYOhCl2/3d+jO1p0hHtm+T/7GgyzkK/lha2 kwts1XvNy2LkA1EHWsFBqU2qb5BKR0Y4DSPHx4Pi0JnRhC9jgGukwjls1ctbtdjHpjaw== X-Received: by 2002:a05:690e:e25:b0:649:c512:1422 with SMTP id 956f58d0204a3-64eaa77e9d1mr1564985d50.42.1773979720476; Thu, 19 Mar 2026 21:08:40 -0700 (PDT) Received: from ryzen ([2601:644:8000:5b5d::8bd]) by smtp.gmail.com with ESMTPSA id 956f58d0204a3-64eabecdbd3sm717558d50.18.2026.03.19.21.08.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Mar 2026 21:08:39 -0700 (PDT) From: Rosen Penev To: linux-leds@vger.kernel.org Cc: Lee Jones , Pavel Machek , Kees Cook , "Gustavo A. R. Silva" , linux-kernel@vger.kernel.org (open list), linux-hardening@vger.kernel.org (open list:KERNEL HARDENING (not covered by other areas):Keyword:\b__counted_by(_le|_be)?\b) Subject: [PATCH] leds: pca955x: kzalloc + kcalloc to single kzalloc Date: Thu, 19 Mar 2026 21:08:21 -0700 Message-ID: <20260320040821.46540-1-rosenp@gmail.com> X-Mailer: git-send-email 2.53.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Two fewer allocations as a result. Required placing some structs before others as flexible array members require a complete definition. Declaration is not enough. Added __counted_by support for one of the structs for extra runtime analysis. Signed-off-by: Rosen Penev --- drivers/leds/leds-pca955x.c | 45 ++++++++++++++----------------------- 1 file changed, 17 insertions(+), 28 deletions(-) diff --git a/drivers/leds/leds-pca955x.c b/drivers/leds/leds-pca955x.c index 2007fe6217ec..ee5f02eaa3c9 100644 --- a/drivers/leds/leds-pca955x.c +++ b/drivers/leds/leds-pca955x.c @@ -112,19 +112,6 @@ static const struct pca955x_chipdef pca955x_chipdefs[]= =3D { }, }; =20 -struct pca955x { - struct mutex lock; - struct pca955x_led *leds; - const struct pca955x_chipdef *chipdef; - struct i2c_client *client; - unsigned long active_blink; - unsigned long active_pins; - unsigned long blink_period; -#ifdef CONFIG_LEDS_PCA955X_GPIO - struct gpio_chip gpio; -#endif -}; - struct pca955x_led { struct pca955x *pca955x; struct led_classdev led_cdev; @@ -137,8 +124,21 @@ struct pca955x_led { #define led_to_pca955x(l) container_of(l, struct pca955x_led, led_cdev) =20 struct pca955x_platform_data { - struct pca955x_led *leds; int num_leds; + struct pca955x_led leds[] __counted_by(num_leds); +}; + +struct pca955x { + struct mutex lock; + const struct pca955x_chipdef *chipdef; + struct i2c_client *client; + unsigned long active_blink; + unsigned long active_pins; + unsigned long blink_period; +#ifdef CONFIG_LEDS_PCA955X_GPIO + struct gpio_chip gpio; +#endif + struct pca955x_led leds[]; }; =20 /* 8 bits per input register */ @@ -542,15 +542,11 @@ pca955x_get_pdata(struct i2c_client *client, const st= ruct pca955x_chipdef *chip) if (count > chip->bits) return ERR_PTR(-ENODEV); =20 - pdata =3D devm_kzalloc(&client->dev, sizeof(*pdata), GFP_KERNEL); + pdata =3D devm_kzalloc(&client->dev, struct_size(pdata, leds, chip->bits)= , GFP_KERNEL); if (!pdata) return ERR_PTR(-ENOMEM); =20 - pdata->leds =3D devm_kcalloc(&client->dev, - chip->bits, sizeof(struct pca955x_led), - GFP_KERNEL); - if (!pdata->leds) - return ERR_PTR(-ENOMEM); + pdata->num_leds =3D chip->bits; =20 device_for_each_child_node(&client->dev, child) { u32 reg; @@ -568,8 +564,6 @@ pca955x_get_pdata(struct i2c_client *client, const stru= ct pca955x_chipdef *chip) fwnode_property_read_u32(child, "type", &led->type); } =20 - pdata->num_leds =3D chip->bits; - return pdata; } =20 @@ -623,15 +617,10 @@ static int pca955x_probe(struct i2c_client *client) return -ENODEV; } =20 - pca955x =3D devm_kzalloc(&client->dev, sizeof(*pca955x), GFP_KERNEL); + pca955x =3D devm_kzalloc(&client->dev, struct_size(pca955x, leds, chip->b= its), GFP_KERNEL); if (!pca955x) return -ENOMEM; =20 - pca955x->leds =3D devm_kcalloc(&client->dev, chip->bits, - sizeof(*pca955x_led), GFP_KERNEL); - if (!pca955x->leds) - return -ENOMEM; - i2c_set_clientdata(client, pca955x); =20 mutex_init(&pca955x->lock); --=20 2.53.0