Message ID | 20171001193101.8898-14-jeremy.lefaure@lse.epita.fr (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
On Sun, Oct 01, 2017 at 03:30:51PM -0400, Jérémy Lefaure wrote: > Using the ARRAY_SIZE macro improves the readability of the code. > > Found with Coccinelle with the following semantic patch: > @r depends on (org || report)@ > type T; > T[] E; > position p; > @@ > ( > (sizeof(E)@p /sizeof(*E)) > | > (sizeof(E)@p /sizeof(E[...])) > | > (sizeof(E)@p /sizeof(T)) > ) > > Signed-off-by: Jérémy Lefaure <jeremy.lefaure@lse.epita.fr> Reviewed-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com> /Jarkko > --- > drivers/char/tpm/tpm_tis.c | 3 ++- > 1 file changed, 2 insertions(+), 1 deletion(-) > > diff --git a/drivers/char/tpm/tpm_tis.c b/drivers/char/tpm/tpm_tis.c > index ebd0e75a3e4d..e2d1055fb814 100644 > --- a/drivers/char/tpm/tpm_tis.c > +++ b/drivers/char/tpm/tpm_tis.c > @@ -30,6 +30,7 @@ > #include <linux/freezer.h> > #include <linux/of.h> > #include <linux/of_device.h> > +#include <linux/kernel.h> > #include "tpm.h" > #include "tpm_tis_core.h" > > @@ -365,7 +366,7 @@ static struct pnp_driver tis_pnp_driver = { > }, > }; > > -#define TIS_HID_USR_IDX sizeof(tpm_pnp_tbl)/sizeof(struct pnp_device_id) -2 > +#define TIS_HID_USR_IDX (ARRAY_SIZE(tpm_pnp_tbl) - 2) > module_param_string(hid, tpm_pnp_tbl[TIS_HID_USR_IDX].id, > sizeof(tpm_pnp_tbl[TIS_HID_USR_IDX].id), 0444); > MODULE_PARM_DESC(hid, "Set additional specific HID for this driver to probe"); > -- > 2.14.1 >
On Wed, 4 Oct 2017 15:14:49 +0300 Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com> wrote: > On Sun, Oct 01, 2017 at 03:30:51PM -0400, Jérémy Lefaure wrote: > > Using the ARRAY_SIZE macro improves the readability of the code. > > > > Found with Coccinelle with the following semantic patch: > > @r depends on (org || report)@ > > type T; > > T[] E; > > position p; > > @@ > > ( > > (sizeof(E)@p /sizeof(*E)) > > | > > (sizeof(E)@p /sizeof(E[...])) > > | > > (sizeof(E)@p /sizeof(T)) > > ) > > > > Signed-off-by: Jérémy Lefaure <jeremy.lefaure@lse.epita.fr> > > Reviewed-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com> > Hi Jarkko, This patch is an individual patch, it's not really part of a series (my fault, sorry). Could you apply this patch to your tree ? Thank you, Jérémy
On Tue, Oct 10, 2017 at 04:30:11PM -0400, Jérémy Lefaure wrote: > On Wed, 4 Oct 2017 15:14:49 +0300 > Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com> wrote: > > > On Sun, Oct 01, 2017 at 03:30:51PM -0400, Jérémy Lefaure wrote: > > > Using the ARRAY_SIZE macro improves the readability of the code. > > > > > > Found with Coccinelle with the following semantic patch: > > > @r depends on (org || report)@ > > > type T; > > > T[] E; > > > position p; > > > @@ > > > ( > > > (sizeof(E)@p /sizeof(*E)) > > > | > > > (sizeof(E)@p /sizeof(E[...])) > > > | > > > (sizeof(E)@p /sizeof(T)) > > > ) > > > > > > Signed-off-by: Jérémy Lefaure <jeremy.lefaure@lse.epita.fr> > > > > Reviewed-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com> > > > Hi Jarkko, > This patch is an individual patch, it's not really part of a series > (my fault, sorry). > > Could you apply this patch to your tree ? > > Thank you, > Jérémy It is already applied :-) I'll take it as part of my next pull request. Thank you. /JarkkO
diff --git a/drivers/char/tpm/tpm_tis.c b/drivers/char/tpm/tpm_tis.c index ebd0e75a3e4d..e2d1055fb814 100644 --- a/drivers/char/tpm/tpm_tis.c +++ b/drivers/char/tpm/tpm_tis.c @@ -30,6 +30,7 @@ #include <linux/freezer.h> #include <linux/of.h> #include <linux/of_device.h> +#include <linux/kernel.h> #include "tpm.h" #include "tpm_tis_core.h" @@ -365,7 +366,7 @@ static struct pnp_driver tis_pnp_driver = { }, }; -#define TIS_HID_USR_IDX sizeof(tpm_pnp_tbl)/sizeof(struct pnp_device_id) -2 +#define TIS_HID_USR_IDX (ARRAY_SIZE(tpm_pnp_tbl) - 2) module_param_string(hid, tpm_pnp_tbl[TIS_HID_USR_IDX].id, sizeof(tpm_pnp_tbl[TIS_HID_USR_IDX].id), 0444); MODULE_PARM_DESC(hid, "Set additional specific HID for this driver to probe");
Using the ARRAY_SIZE macro improves the readability of the code. Found with Coccinelle with the following semantic patch: @r depends on (org || report)@ type T; T[] E; position p; @@ ( (sizeof(E)@p /sizeof(*E)) | (sizeof(E)@p /sizeof(E[...])) | (sizeof(E)@p /sizeof(T)) ) Signed-off-by: Jérémy Lefaure <jeremy.lefaure@lse.epita.fr> --- drivers/char/tpm/tpm_tis.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)