usb: typec: qcom-pmic-typec: simplify allocation
PATCH v2 1/1 usb: typec: qcom-pmic-typec: simplify allocation
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.
---
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(-)
drivers/usb/typec/tcpm/qcom/qcom_pmic_typec_pdphy.c +10 -13
@@ -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;
drivers/usb/typec/tcpm/qcom/qcom_pmic_typec_port.c +10 -12
@@ -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
Bryan O'Donoghue
maintainerQuoted 8 lines · Rosen Penev
Change kzalloc + kcalloc to just kzalloc with a flexible array member.
Add
__counted_byfor extra runtime analysis when requested.Move counting assignment immediately after allocation as required by
__counted_by.Signed-off-by Rosen Penev <[email protected]>
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
Quoted 15 lines · Bryan O'Donoghue
Quoted 8 lines · Rosen Penev
Change kzalloc + kcalloc to just kzalloc with a flexible array member.
Add
__counted_byfor extra runtime analysis when requested.Move counting assignment immediately after allocation as required by
__counted_by.Signed-off-by Rosen Penev <[email protected]>Hi Rosen.
Thanks for your patch.
Quoted 7 lines
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.
Quoted 5 lines
[PATCH v3 2/3] Add
__counted_byfor 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.
Quoted 5 lines
Or something pretty close to that.
There are several reasons for that
Quoted 8 lines
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.
Quoted 9 lines
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.
Quoted 4 lines
Oh and reason 4 is the most important !
Patch count bragging rights !
That's just pointless churn.
Quoted 3 lines
---
bod
Bryan O'Donoghue
maintainerQuoted 2 lines · Rosen Penev
Quoted 1 line
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