From: Jani Nikula <jani.nikula@linux.intel.com>
To: Zhenyu Wang <zhenyuw@linux.intel.com>,
Zhi Wang <zhi.a.wang@intel.com>,
Joonas Lahtinen <joonas.lahtinen@linux.intel.com>,
Rodrigo Vivi <rodrigo.vivi@intel.com>
Cc: "Jérémy Lefaure" <jeremy.lefaure@lse.epita.fr>,
intel-gfx@lists.freedesktop.org,
intel-gvt-dev@lists.freedesktop.org
Subject: Re: [PATCH] drm/i915/gvt: use ARRAY_SIZE
Date: Mon, 16 Oct 2017 12:34:49 +0300 [thread overview]
Message-ID: <87h8uzmo5i.fsf@intel.com> (raw)
In-Reply-To: <20171016023207.19561-1-jeremy.lefaure@lse.epita.fr>
[dropped a number of lists and maintainers, please use common sense]
On Sun, 15 Oct 2017, Jérémy Lefaure <jeremy.lefaure@lse.epita.fr> wrote:
> Using the ARRAY_SIZE macro improves the readability of the code. Also,
> it's useless to use a variable to store this constant calculated at
> compile time.
I'll leave it up to Zhenyu and Zhi, but IMHO the variable is not
useless. It improves the readability of the code by giving a name to the
information, and the compiler will throw it away. Either way,
Reviewed-by: Jani Nikula <jani.nikula@intel.com>
(Up next, someone sends another patch to change the kzalloc to
kcalloc... *sigh*)
>
> 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>
> ---
> This patch was part of a bigger patch [1].
>
> [1]: https://patchwork.kernel.org/patch/9979843/
>
> drivers/gpu/drm/i915/gvt/vgpu.c | 9 ++++-----
> 1 file changed, 4 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/gpu/drm/i915/gvt/vgpu.c b/drivers/gpu/drm/i915/gvt/vgpu.c
> index 02c61a1ad56a..b32c1c889ea8 100644
> --- a/drivers/gpu/drm/i915/gvt/vgpu.c
> +++ b/drivers/gpu/drm/i915/gvt/vgpu.c
> @@ -31,6 +31,7 @@
> *
> */
>
> +#include <linux/kernel.h>
> #include "i915_drv.h"
> #include "gvt.h"
> #include "i915_pvinfo.h"
> @@ -98,7 +99,6 @@ static struct {
> */
> int intel_gvt_init_vgpu_types(struct intel_gvt *gvt)
> {
> - unsigned int num_types;
> unsigned int i, low_avail, high_avail;
> unsigned int min_low;
>
> @@ -116,15 +116,14 @@ int intel_gvt_init_vgpu_types(struct intel_gvt *gvt)
> */
> low_avail = gvt_aperture_sz(gvt) - HOST_LOW_GM_SIZE;
> high_avail = gvt_hidden_sz(gvt) - HOST_HIGH_GM_SIZE;
> - num_types = sizeof(vgpu_types) / sizeof(vgpu_types[0]);
>
> - gvt->types = kzalloc(num_types * sizeof(struct intel_vgpu_type),
> - GFP_KERNEL);
> + gvt->types = kzalloc(ARRAY_SIZE(vgpu_types) *
> + sizeof(struct intel_vgpu_type), GFP_KERNEL);
> if (!gvt->types)
> return -ENOMEM;
>
> min_low = MB_TO_BYTES(32);
> - for (i = 0; i < num_types; ++i) {
> + for (i = 0; i < ARRAY_SIZE(vgpu_types); ++i) {
> if (low_avail / vgpu_types[i].low_mm == 0)
> break;
--
Jani Nikula, Intel Open Source Technology Center
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
next prev parent reply other threads:[~2017-10-16 9:34 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-10-16 2:32 [PATCH] drm/i915/gvt: use ARRAY_SIZE Jérémy Lefaure
2017-10-16 2:32 ` Jérémy Lefaure
2017-10-16 2:55 ` ✓ Fi.CI.BAT: success for " Patchwork
2017-10-16 4:01 ` ✓ Fi.CI.IGT: " Patchwork
2017-10-16 9:34 ` Jani Nikula [this message]
2017-10-16 9:37 ` [PATCH] " Wang, Zhi A
2017-10-23 16:38 ` Zhi Wang
2017-10-23 16:38 ` Zhi Wang
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87h8uzmo5i.fsf@intel.com \
--to=jani.nikula@linux.intel.com \
--cc=intel-gfx@lists.freedesktop.org \
--cc=intel-gvt-dev@lists.freedesktop.org \
--cc=jeremy.lefaure@lse.epita.fr \
--cc=joonas.lahtinen@linux.intel.com \
--cc=rodrigo.vivi@intel.com \
--cc=zhenyuw@linux.intel.com \
--cc=zhi.a.wang@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.