Message ID | 42a87fb9837f1760d1ad4eb7162a7536785dc6f5.1712520052.git.christophe.jaillet@wanadoo.fr |
---|---|
State | New |
Headers | show |
Series | [1/2] thermal/drivers/mediatek/lvts_thermal: Make debugfs related fields more consistent | expand |
On Sun, Apr 07, 2024 at 10:01:49PM +0200, Christophe JAILLET wrote: > diff --git a/drivers/thermal/mediatek/lvts_thermal.c b/drivers/thermal/mediatek/lvts_thermal.c > index 3003dc350766..b133f731c5ba 100644 > --- a/drivers/thermal/mediatek/lvts_thermal.c > +++ b/drivers/thermal/mediatek/lvts_thermal.c > @@ -204,7 +204,7 @@ static const struct debugfs_reg32 lvts_regs[] = { > > static int lvts_debugfs_init(struct device *dev, struct lvts_domain *lvts_td) > { > - struct debugfs_regset32 *regset; > + struct debugfs_regset32 *regsets; > struct lvts_ctrl *lvts_ctrl; > struct dentry *dentry; > char name[64]; > @@ -214,8 +214,14 @@ static int lvts_debugfs_init(struct device *dev, struct lvts_domain *lvts_td) > if (IS_ERR(lvts_td->dom_dentry)) > return 0; > > + regsets = devm_kcalloc(dev, lvts_td->num_lvts_ctrl, > + sizeof(*regsets), GFP_KERNEL); > + if (!regsets) > + return 0; I understand that this preserved the behavior from the original code, but the original code was wrong. This should return -ENOMEM. > + > for (i = 0; i < lvts_td->num_lvts_ctrl; i++) { > > + struct debugfs_regset32 *regset = ®sets[i]; > lvts_ctrl = &lvts_td->lvts_ctrl[i]; The blank line should come after the declaration. regards, dan carpenter
Le 08/04/2024 à 10:09, Dan Carpenter a écrit : > On Sun, Apr 07, 2024 at 10:01:49PM +0200, Christophe JAILLET wrote: >> diff --git a/drivers/thermal/mediatek/lvts_thermal.c b/drivers/thermal/mediatek/lvts_thermal.c >> index 3003dc350766..b133f731c5ba 100644 >> --- a/drivers/thermal/mediatek/lvts_thermal.c >> +++ b/drivers/thermal/mediatek/lvts_thermal.c >> @@ -204,7 +204,7 @@ static const struct debugfs_reg32 lvts_regs[] = { >> >> static int lvts_debugfs_init(struct device *dev, struct lvts_domain *lvts_td) >> { >> - struct debugfs_regset32 *regset; >> + struct debugfs_regset32 *regsets; >> struct lvts_ctrl *lvts_ctrl; >> struct dentry *dentry; >> char name[64]; >> @@ -214,8 +214,14 @@ static int lvts_debugfs_init(struct device *dev, struct lvts_domain *lvts_td) >> if (IS_ERR(lvts_td->dom_dentry)) >> return 0; >> >> + regsets = devm_kcalloc(dev, lvts_td->num_lvts_ctrl, >> + sizeof(*regsets), GFP_KERNEL); >> + if (!regsets) >> + return 0; > > I understand that this preserved the behavior from the original code, > but the original code was wrong. This should return -ENOMEM. Hi Dan, I don't agree. For me, this memory allocation is of the same type as all debugfs functions that we ignore the error code. If it fails, it is not a reason good enough to have the probe fail. (anyway, if we are short on memory at this point other errors will likely occur) > >> + >> for (i = 0; i < lvts_td->num_lvts_ctrl; i++) { >> >> + struct debugfs_regset32 *regset = ®sets[i]; >> lvts_ctrl = &lvts_td->lvts_ctrl[i]; > > The blank line should come after the declaration. The blank line was already there, and in this file, it looks like the preferred style (even if not completely consistent) Let see if there is some comment about 0 or -ENOMEM in case of memory allocation error, and if needed, I'll repost without the blank line. This patch being a really tiny tiny tiny improvement (IMHO), so it may also just be ignored. CJ > > regards, > dan carpenter > > >
diff --git a/drivers/thermal/mediatek/lvts_thermal.c b/drivers/thermal/mediatek/lvts_thermal.c index fd4bd650c77a..3003dc350766 100644 --- a/drivers/thermal/mediatek/lvts_thermal.c +++ b/drivers/thermal/mediatek/lvts_thermal.c @@ -150,7 +150,7 @@ struct lvts_domain { void __iomem *base; size_t calib_len; u8 *calib; -#ifdef CONFIG_DEBUG_FS +#ifdef CONFIG_MTK_LVTS_THERMAL_DEBUGFS struct dentry *dom_dentry; #endif };
The debugfs code is only generated if CONFIG_MTK_LVTS_THERMAL_DEBUGFS is defined. So 'dom_dentry' should be included in the 'struct lvts_domain' with the same condition, instead of CONFIG_DEBUG_FS. Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr> --- Compile tested-only --- drivers/thermal/mediatek/lvts_thermal.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)