From nobody Thu Apr 2 23:54:12 2026 Received: from mail-pf1-f177.google.com (mail-pf1-f177.google.com [209.85.210.177]) (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 CCD8225B31D for ; Thu, 26 Mar 2026 02:36:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.177 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774492607; cv=none; b=OIHLnb+ieApL3CczngzqTwxi6ooEH67esX7Ar4bY6ahUogc5V2PALvKCYj4wAnM/aK5ZqjVzyQW+6qaui+vGyqxUxMU7K3cV/Ji67QAMybU9x7dd7f9T857AOxmSbPj8KaoDGS8aoYS0a5UpDalARAZnp7SyhrKR4AUsQSJxbLc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774492607; c=relaxed/simple; bh=x9AzjzvF+Zn/f58SEXBbdYUK8/A08m9vI2LlTEJCV7Q=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=Jv4o8yIk9BdEMcV4/l4wF9ZHfZNwgmaWdlbtWYVTiIa/FJ/MjL9FsWaRjSvaBmaIJADfBpX/nmPGv9hHVOTcOHtx/BFJ/2KphZQdBY+rGc4IaIwIyQE4rUhawMLVAPRhISG4BOTb3t43VbZibAQlFV5+3XdeIf6PZq/05FliATY= 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=C+QhDHRt; arc=none smtp.client-ip=209.85.210.177 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="C+QhDHRt" Received: by mail-pf1-f177.google.com with SMTP id d2e1a72fcca58-8296d553142so246382b3a.3 for ; Wed, 25 Mar 2026 19:36:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1774492605; x=1775097405; 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=dc94mFyUarnXD7uTGOHIqKLXmGuXftbJg5Kgbu68aTI=; b=C+QhDHRtemAh95GLVEXIKzkv7aytG5q8dF+9ChKxMy7ty6zd3mE8rcD0QMPTiVWtjK iziO+56iB68d/OxpWjMhTc1g/o/yu5UL2HOPJrpiX+seDk4ParjTIuj1AKmAJIM1i2zI Odpg97Ma4jJB9XT4VFxf7vOl/tOd603zow4uQzr5SdR3O+6JV4swleSlTA85dNCVwRms UvbrqYSKbOaCVGQj5BS5ej0x6W+ZvVa1Ojo686vKtDvrH+3pIjeiqH8ksxVDJ2WKOt/P vfdqW4A4OERRpAdLjZauIZKIvC/yaBBd649hzpBBUYfBOwdJfk4EW8Do/v/I3cs63BJK p0nA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1774492605; x=1775097405; 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=dc94mFyUarnXD7uTGOHIqKLXmGuXftbJg5Kgbu68aTI=; b=PQUxFXMpK5rcfpII84sE8K/GA5E8tBGsP1t3/xHvMyQNz+2qd7Aujo3UNSC0K77zWj qWhrNWIjG6ucngt3UD5MrGW7Z8g5O+CsCep0d/eYxtBEkEG4HM0345GEYZgmtmgBnAtM c++/3gYqgU11zGG8q7DpAF2eu6D43gMXBzuVrGHsFqJz9txZZjrEyvipYHpE4b7Ios9M dogcHkodS6HzO5poU7DdOu+H5GrtalkF545hDQUamNT4u6Xr0BMEscFyRf+X4hyy1zQc eXRD7TjkzTz0OnpzLkPgt2dUjLcyqDzW7zUzm/FwHmnJXOJtiAsAK2TbxPOM3+D4mCj9 7HDw== X-Forwarded-Encrypted: i=1; AJvYcCXBd1klgLD8WnUNJzD063CCBJq4ALlO1eShxSll9DnCivvnkTSshpmWQ2dwLAeNqYtL7dJSn41OHQNHVZs=@vger.kernel.org X-Gm-Message-State: AOJu0Yzd9i8P19/8AhpMiPsiKF+z0PXVpHXrdhJCER39CukkGZ6ja2Ur jC6XZ4vRa1mlaCP4GzEWW7oLmke6epk/DuBCXJY7Hg1oKDTqKeeCXz8I X-Gm-Gg: ATEYQzxY6paKLhmUiNmZXZfLRVP6viOYC/GipHUIO1wptmhamGwQ3rDagI3/Ifs/N1z tGvz9A6hJ7goJ5qe61EIuqMB4KGbn6muRLK0IAErf6vo6rUkJQoqmSdEFiPcROTcnXac1nirY0p +fRcv1g28WjnE7j3UcvSZBcXM1daUbJvNfWdFuQnGxmrqWWjf7IsUY34ak3W0Bfe45HvCjRzvPq x5DIrE/sVdNhmJwXLK0a+DtZDvcJJuuuczhTwWab3rfBzNTiKezN26JhxWCYC/hnEzu4KETEFBo MVVtjUfYpmhEFfV810aoE0M0rfljDw3hDKXnGYTTCIWiZ6lWVd08Dwg43gdfK/VQ0IvZR6kMR0N 4PN75MuTE62uo4G/XR5OtecbHow5g5+96Z1yHXHcNFhFXeturXV22DmgiAwa9pc+4CcCrHcdOca Ci4W0+2bXhP3Pk+mDzpCY2KZxe8PaRC2h/WvYLwW64imJeNLAnz36WVo97Mh83aXWXAw== X-Received: by 2002:a05:6a00:f05:b0:82a:6de8:fa4e with SMTP id d2e1a72fcca58-82c6de9f009mr6630975b3a.17.1774492604974; Wed, 25 Mar 2026 19:36:44 -0700 (PDT) Received: from ryzen ([2601:644:8000:5b5d::8bd]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-82c7d385601sm990176b3a.33.2026.03.25.19.36.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Mar 2026 19:36:44 -0700 (PDT) From: Rosen Penev To: linux-gpio@vger.kernel.org Cc: Mika Westerberg , Andy Shevchenko , Linus Walleij , 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] pinctrl: intel: use FAM for communities Date: Wed, 25 Mar 2026 19:36:27 -0700 Message-ID: <20260326023627.54349-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" Use a flexible array member to combine allocations into one. Add __counted_by for extra runtime analysis. Move counting variable assignments to after allocation as required by __counted_by. Signed-off-by: Rosen Penev --- drivers/pinctrl/intel/pinctrl-baytrail.c | 43 +++++++--------------- drivers/pinctrl/intel/pinctrl-cherryview.c | 11 ++---- drivers/pinctrl/intel/pinctrl-intel.c | 15 ++------ drivers/pinctrl/intel/pinctrl-intel.h | 2 +- drivers/pinctrl/intel/pinctrl-lynxpoint.c | 9 +---- 5 files changed, 25 insertions(+), 55 deletions(-) diff --git a/drivers/pinctrl/intel/pinctrl-baytrail.c b/drivers/pinctrl/int= el/pinctrl-baytrail.c index b733ec31ad9d..e73419498857 100644 --- a/drivers/pinctrl/intel/pinctrl-baytrail.c +++ b/drivers/pinctrl/intel/pinctrl-baytrail.c @@ -1558,31 +1558,6 @@ static int byt_gpio_probe(struct intel_pinctrl *vg) return 0; } =20 -static int byt_set_soc_data(struct intel_pinctrl *vg, - const struct intel_pinctrl_soc_data *soc) -{ - struct platform_device *pdev =3D to_platform_device(vg->dev); - int i; - - vg->soc =3D soc; - - vg->ncommunities =3D vg->soc->ncommunities; - vg->communities =3D devm_kmemdup_array(vg->dev, vg->soc->communities, vg-= >ncommunities, - sizeof(*vg->soc->communities), GFP_KERNEL); - if (!vg->communities) - return -ENOMEM; - - for (i =3D 0; i < vg->soc->ncommunities; i++) { - struct intel_community *comm =3D vg->communities + i; - - comm->pad_regs =3D devm_platform_ioremap_resource(pdev, 0); - if (IS_ERR(comm->pad_regs)) - return PTR_ERR(comm->pad_regs); - } - - return 0; -} - static const struct acpi_device_id byt_gpio_acpi_match[] =3D { { "INT33B2", (kernel_ulong_t)byt_soc_data }, { "INT33FC", (kernel_ulong_t)byt_soc_data }, @@ -1595,19 +1570,29 @@ static int byt_pinctrl_probe(struct platform_device= *pdev) struct device *dev =3D &pdev->dev; struct intel_pinctrl *vg; int ret; + int i; =20 soc_data =3D intel_pinctrl_get_soc_data(pdev); if (IS_ERR(soc_data)) return PTR_ERR(soc_data); =20 - vg =3D devm_kzalloc(dev, sizeof(*vg), GFP_KERNEL); + vg =3D devm_kzalloc(dev, struct_size(vg, communities, soc_data->ncommunit= ies), GFP_KERNEL); if (!vg) return -ENOMEM; =20 + vg->ncommunities =3D soc_data->ncommunities; + memcpy(vg->communities, soc_data->communities, soc_data->ncommunities * s= izeof(*vg->communities)); + vg->dev =3D dev; - ret =3D byt_set_soc_data(vg, soc_data); - if (ret) - return dev_err_probe(dev, ret, "failed to set soc data\n"); + vg->soc =3D soc_data; + + for (i =3D 0; i < vg->soc->ncommunities; i++) { + struct intel_community *comm =3D vg->communities + i; + + comm->pad_regs =3D devm_platform_ioremap_resource(pdev, 0); + if (IS_ERR(comm->pad_regs)) + return PTR_ERR(comm->pad_regs); + } =20 vg->pctldesc =3D byt_pinctrl_desc; vg->pctldesc.name =3D dev_name(dev); diff --git a/drivers/pinctrl/intel/pinctrl-cherryview.c b/drivers/pinctrl/i= ntel/pinctrl-cherryview.c index a33eca5eafc4..e9b062b44fea 100644 --- a/drivers/pinctrl/intel/pinctrl-cherryview.c +++ b/drivers/pinctrl/intel/pinctrl-cherryview.c @@ -1595,19 +1595,16 @@ static int chv_pinctrl_probe(struct platform_device= *pdev) if (IS_ERR(soc_data)) return PTR_ERR(soc_data); =20 - pctrl =3D devm_kzalloc(dev, sizeof(*pctrl), GFP_KERNEL); + pctrl =3D devm_kzalloc(dev, struct_size(pctrl, communities, soc_data->nco= mmunities), GFP_KERNEL); if (!pctrl) return -ENOMEM; =20 + pctrl->ncommunities =3D soc_data->ncommunities; + memcpy(pctrl->communities, soc_data->communities, soc_data->ncommunities = * sizeof(*pctrl->communities)); + pctrl->dev =3D dev; pctrl->soc =3D soc_data; =20 - pctrl->ncommunities =3D pctrl->soc->ncommunities; - pctrl->communities =3D devm_kmemdup_array(dev, pctrl->soc->communities, p= ctrl->ncommunities, - sizeof(*pctrl->soc->communities), GFP_KERNEL); - if (!pctrl->communities) - return -ENOMEM; - community =3D &pctrl->communities[0]; community->regs =3D devm_platform_ioremap_resource(pdev, 0); if (IS_ERR(community->regs)) diff --git a/drivers/pinctrl/intel/pinctrl-intel.c b/drivers/pinctrl/intel/= pinctrl-intel.c index 97bf5ec78db4..635e4e5ab10c 100644 --- a/drivers/pinctrl/intel/pinctrl-intel.c +++ b/drivers/pinctrl/intel/pinctrl-intel.c @@ -1581,24 +1581,17 @@ int intel_pinctrl_probe(struct platform_device *pde= v, struct intel_pinctrl *pctrl; int i, ret, irq; =20 - pctrl =3D devm_kzalloc(dev, sizeof(*pctrl), GFP_KERNEL); + pctrl =3D devm_kzalloc(dev, struct_size(pctrl, communities, soc_data->nco= mmunities), GFP_KERNEL); if (!pctrl) return -ENOMEM; =20 + pctrl->ncommunities =3D soc_data->ncommunities; + memcpy(pctrl->communities, soc_data->communities, soc_data->ncommunities = * sizeof(*pctrl->communities)); + pctrl->dev =3D dev; pctrl->soc =3D soc_data; raw_spin_lock_init(&pctrl->lock); =20 - /* - * Make a copy of the communities which we can use to hold pointers - * to the registers. - */ - pctrl->ncommunities =3D pctrl->soc->ncommunities; - pctrl->communities =3D devm_kmemdup_array(dev, pctrl->soc->communities, p= ctrl->ncommunities, - sizeof(*pctrl->soc->communities), GFP_KERNEL); - if (!pctrl->communities) - return -ENOMEM; - for (i =3D 0; i < pctrl->ncommunities; i++) { struct intel_community *community =3D &pctrl->communities[i]; unsigned short capability_offset[6]; diff --git a/drivers/pinctrl/intel/pinctrl-intel.h b/drivers/pinctrl/intel/= pinctrl-intel.h index b5476b9de0db..c382fe8f08c2 100644 --- a/drivers/pinctrl/intel/pinctrl-intel.h +++ b/drivers/pinctrl/intel/pinctrl-intel.h @@ -260,10 +260,10 @@ struct intel_pinctrl { struct pinctrl_dev *pctldev; struct gpio_chip chip; const struct intel_pinctrl_soc_data *soc; - struct intel_community *communities; size_t ncommunities; struct intel_pinctrl_context context; int irq; + struct intel_community communities[] __counted_by(ncommunities); }; =20 int intel_pinctrl_probe(struct platform_device *pdev, diff --git a/drivers/pinctrl/intel/pinctrl-lynxpoint.c b/drivers/pinctrl/in= tel/pinctrl-lynxpoint.c index 299ee4f22bdc..b3cde7afded9 100644 --- a/drivers/pinctrl/intel/pinctrl-lynxpoint.c +++ b/drivers/pinctrl/intel/pinctrl-lynxpoint.c @@ -715,19 +715,14 @@ static int lp_gpio_probe(struct platform_device *pdev) if (!soc) return -ENODEV; =20 - lg =3D devm_kzalloc(dev, sizeof(*lg), GFP_KERNEL); + lg =3D devm_kzalloc(dev, struct_size(lg, communities, soc->ncommunities),= GFP_KERNEL); if (!lg) return -ENOMEM; =20 + lg->ncommunities =3D soc->ncommunities; lg->dev =3D dev; lg->soc =3D soc; =20 - lg->ncommunities =3D lg->soc->ncommunities; - lg->communities =3D devm_kcalloc(dev, lg->ncommunities, - sizeof(*lg->communities), GFP_KERNEL); - if (!lg->communities) - return -ENOMEM; - lg->pctldesc =3D lptlp_pinctrl_desc; lg->pctldesc.name =3D dev_name(dev); lg->pctldesc.pins =3D lg->soc->pins; --=20 2.53.0