.../typec/tcpm/qcom/qcom_pmic_typec_pdphy.c | 23 ++++++++----------- .../typec/tcpm/qcom/qcom_pmic_typec_port.c | 22 ++++++++---------- 2 files changed, 20 insertions(+), 25 deletions(-)
Change kzalloc + kcalloc to just kzalloc with a flexible array member.
Add __counted_by for extra runtime analysis when requested.
Move counting assignment immediately after allocation as required by
__counted_by.
Signed-off-by: Rosen Penev <rosenp@gmail.com>
---
v2: reduce chaanges only to needed ones.
.../typec/tcpm/qcom/qcom_pmic_typec_pdphy.c | 23 ++++++++-----------
.../typec/tcpm/qcom/qcom_pmic_typec_port.c | 22 ++++++++----------
2 files changed, 20 insertions(+), 25 deletions(-)
diff --git a/drivers/usb/typec/tcpm/qcom/qcom_pmic_typec_pdphy.c b/drivers/usb/typec/tcpm/qcom/qcom_pmic_typec_pdphy.c
index c8b1463e6e8b..a1d9315994de 100644
--- a/drivers/usb/typec/tcpm/qcom/qcom_pmic_typec_pdphy.c
+++ b/drivers/usb/typec/tcpm/qcom/qcom_pmic_typec_pdphy.c
@@ -95,13 +95,13 @@ struct pmic_typec_pdphy {
struct regmap *regmap;
u32 base;
- unsigned int nr_irqs;
- struct pmic_typec_pdphy_irq_data *irq_data;
-
struct work_struct reset_work;
struct work_struct receive_work;
struct regulator *vdd_pdphy;
spinlock_t lock; /* Register atomicity */
+
+ unsigned int nr_irqs;
+ struct pmic_typec_pdphy_irq_data irq_data[] __counted_by(nr_irqs);
};
static void qcom_pmic_typec_pdphy_reset_on(struct pmic_typec_pdphy *pmic_typec_pdphy)
@@ -560,18 +560,16 @@ int qcom_pmic_typec_pdphy_probe(struct platform_device *pdev,
struct pmic_typec_pdphy_irq_data *irq_data;
int i, ret, irq;
- pmic_typec_pdphy = devm_kzalloc(dev, sizeof(*pmic_typec_pdphy), GFP_KERNEL);
- if (!pmic_typec_pdphy)
- return -ENOMEM;
-
if (!res->nr_irqs || res->nr_irqs > PMIC_PDPHY_MAX_IRQS)
return -EINVAL;
- irq_data = devm_kcalloc(dev, res->nr_irqs, sizeof(*irq_data),
- GFP_KERNEL);
- if (!irq_data)
+ pmic_typec_pdphy = devm_kzalloc(dev,
+ struct_size(pmic_typec_pdphy, irq_data, res->nr_irqs), GFP_KERNEL);
+ if (!pmic_typec_pdphy)
return -ENOMEM;
+ pmic_typec_pdphy->nr_irqs = res->nr_irqs;
+
pmic_typec_pdphy->vdd_pdphy = devm_regulator_get(dev, "vdd-pdphy");
if (IS_ERR(pmic_typec_pdphy->vdd_pdphy))
return PTR_ERR(pmic_typec_pdphy->vdd_pdphy);
@@ -579,12 +577,11 @@ int qcom_pmic_typec_pdphy_probe(struct platform_device *pdev,
pmic_typec_pdphy->dev = dev;
pmic_typec_pdphy->base = base;
pmic_typec_pdphy->regmap = regmap;
- pmic_typec_pdphy->nr_irqs = res->nr_irqs;
- pmic_typec_pdphy->irq_data = irq_data;
spin_lock_init(&pmic_typec_pdphy->lock);
INIT_WORK(&pmic_typec_pdphy->reset_work, qcom_pmic_typec_pdphy_sig_reset_work);
- for (i = 0; i < res->nr_irqs; i++, irq_data++) {
+ for (i = 0; i < res->nr_irqs; i++) {
+ irq_data = &pmic_typec_pdphy->irq_data[i];
irq = platform_get_irq_byname(pdev, res->irq_params[i].irq_name);
if (irq < 0)
return irq;
diff --git a/drivers/usb/typec/tcpm/qcom/qcom_pmic_typec_port.c b/drivers/usb/typec/tcpm/qcom/qcom_pmic_typec_port.c
index 8051eaa46991..6c6401187f58 100644
--- a/drivers/usb/typec/tcpm/qcom/qcom_pmic_typec_port.c
+++ b/drivers/usb/typec/tcpm/qcom/qcom_pmic_typec_port.c
@@ -169,8 +169,6 @@ struct pmic_typec_port {
struct tcpm_port *tcpm_port;
struct regmap *regmap;
u32 base;
- unsigned int nr_irqs;
- struct pmic_typec_port_irq_data *irq_data;
struct regulator *vdd_vbus;
bool vbus_enabled;
@@ -181,6 +179,9 @@ struct pmic_typec_port {
struct delayed_work cc_debounce_dwork;
spinlock_t lock; /* Register atomicity */
+
+ unsigned int nr_irqs;
+ struct pmic_typec_port_irq_data irq_data[] __counted_by(nr_irqs);
};
static const char * const typec_cc_status_name[] = {
@@ -706,18 +707,16 @@ int qcom_pmic_typec_port_probe(struct platform_device *pdev,
struct pmic_typec_port *pmic_typec_port;
int i, ret, irq;
- pmic_typec_port = devm_kzalloc(dev, sizeof(*pmic_typec_port), GFP_KERNEL);
- if (!pmic_typec_port)
- return -ENOMEM;
-
if (!res->nr_irqs || res->nr_irqs > PMIC_TYPEC_MAX_IRQS)
return -EINVAL;
- irq_data = devm_kcalloc(dev, res->nr_irqs, sizeof(*irq_data),
- GFP_KERNEL);
- if (!irq_data)
+ pmic_typec_port = devm_kzalloc(dev,
+ struct_size(pmic_typec_port, irq_data, res->nr_irqs), GFP_KERNEL);
+ if (!pmic_typec_port)
return -ENOMEM;
+ pmic_typec_port->nr_irqs = res->nr_irqs;
+
mutex_init(&pmic_typec_port->vbus_lock);
pmic_typec_port->vdd_vbus = devm_regulator_get(dev, "vdd-vbus");
@@ -727,8 +726,6 @@ int qcom_pmic_typec_port_probe(struct platform_device *pdev,
pmic_typec_port->dev = dev;
pmic_typec_port->base = base;
pmic_typec_port->regmap = regmap;
- pmic_typec_port->nr_irqs = res->nr_irqs;
- pmic_typec_port->irq_data = irq_data;
spin_lock_init(&pmic_typec_port->lock);
INIT_DELAYED_WORK(&pmic_typec_port->cc_debounce_dwork,
qcom_pmic_typec_port_cc_debounce);
@@ -737,7 +734,8 @@ int qcom_pmic_typec_port_probe(struct platform_device *pdev,
if (irq < 0)
return irq;
- for (i = 0; i < res->nr_irqs; i++, irq_data++) {
+ for (i = 0; i < res->nr_irqs; i++) {
+ irq_data = &pmic_typec_port->irq_data[i];
irq = platform_get_irq_byname(pdev,
res->irq_params[i].irq_name);
if (irq < 0)
--
2.53.0
On 11/03/2026 23:23, Rosen Penev wrote:
> Change kzalloc + kcalloc to just kzalloc with a flexible array member.
>
> Add __counted_by for extra runtime analysis when requested.
>
> Move counting assignment immediately after allocation as required by
> __counted_by.
>
> Signed-off-by: Rosen Penev <rosenp@gmail.com>
Hi Rosen.
Thanks for your patch.
I have the same feedback as Greg gave you previously on this.
Each line-item in your log should really be its own patch i.e. v3 should
be three patches
[PATCH v3 1/3] Change kzalloc + kcalloc to just kzalloc with a flexible
array member.
[PATCH v3 2/3] Add __counted_by for extra runtime analysis when requested.
[PATCH v3 3/3] Move counting assignment immediately after allocation as
required by __counted_by.
Or something pretty close to that.
There are several reasons for that
1. Bisectability
The ability to more easily bisect patches.
2. Logical separation
If a change deserves its own line-item in a patch
then that change almost certainly deserves its own patch.
3. Mixing stuff up in a big patch is confusing
I look at a commit log and see lots of things going on in one go.
I as a reviewer or say someone tracking -stable and deciding which
patches to pull into my tree can't look at a patch a "just know" what
it is doing.
So v3 should please
- Have a cover letter
- Contain three patches one for each logical change
Oh and reason 4 is the most important !
Patch count bragging rights !
---
bod
On Wed, Mar 11, 2026 at 4:37 PM Bryan O'Donoghue <bryan.odonoghue@linaro.org> wrote: > > On 11/03/2026 23:23, Rosen Penev wrote: > > Change kzalloc + kcalloc to just kzalloc with a flexible array member. > > > > Add __counted_by for extra runtime analysis when requested. > > > > Move counting assignment immediately after allocation as required by > > __counted_by. > > > > Signed-off-by: Rosen Penev <rosenp@gmail.com> > > Hi Rosen. > > Thanks for your patch. > > I have the same feedback as Greg gave you previously on this. > > Each line-item in your log should really be its own patch i.e. v3 should > be three patches > > [PATCH v3 1/3] Change kzalloc + kcalloc to just kzalloc with a flexible > array member. This is probably the only one worth anything. I'm getting requests elsewhere to add __counted_by though. > > [PATCH v3 2/3] Add __counted_by for extra runtime analysis when requested. > > [PATCH v3 3/3] Move counting assignment immediately after allocation as > required by __counted_by. 2 and 3 as you laid out should be the same. 2 without 3 breaks runtime analysis. > > Or something pretty close to that. > > There are several reasons for that > > 1. Bisectability > The ability to more easily bisect patches. > > 2. Logical separation > If a change deserves its own line-item in a patch > then that change almost certainly deserves its own patch. > > 3. Mixing stuff up in a big patch is confusing calling 20 insertions(+), 25 deletions(-) big is wild. > I look at a commit log and see lots of things going on in one go. > I as a reviewer or say someone tracking -stable and deciding which > patches to pull into my tree can't look at a patch a "just know" what > it is doing. > > So v3 should please > > - Have a cover letter > - Contain three patches one for each logical change Maybe some other time. > > Oh and reason 4 is the most important ! > > Patch count bragging rights ! That's just pointless churn. > > --- > bod
On 12/03/2026 00:12, Rosen Penev wrote: >> Patch count bragging rights ! > That's just pointless churn. Obviously the most important part of all. In all seriousness though, just break it up a bit plz/ty. --- bod
© 2016 - 2026 Red Hat, Inc.