All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] drm/i915/gvt: use ARRAY_SIZE
@ 2017-10-16  2:32 ` Jérémy Lefaure
  0 siblings, 0 replies; 8+ messages in thread
From: Jérémy Lefaure @ 2017-10-16  2:32 UTC (permalink / raw)
  To: Zhenyu Wang, Zhi Wang, Jani Nikula, Joonas Lahtinen, Rodrigo Vivi,
	David Airlie
  Cc: Jérémy Lefaure, intel-gfx, intel-gvt-dev, linux-kernel,
	dri-devel

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.

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;
 
-- 
2.14.2

_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH] drm/i915/gvt: use ARRAY_SIZE
@ 2017-10-16  2:32 ` Jérémy Lefaure
  0 siblings, 0 replies; 8+ messages in thread
From: Jérémy Lefaure @ 2017-10-16  2:32 UTC (permalink / raw)
  To: Zhenyu Wang, Zhi Wang, Jani Nikula, Joonas Lahtinen, Rodrigo Vivi,
	David Airlie
  Cc: Jérémy Lefaure, intel-gvt-dev, intel-gfx, dri-devel,
	linux-kernel

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.

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;
 
-- 
2.14.2

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* ✓ Fi.CI.BAT: success for drm/i915/gvt: use ARRAY_SIZE
  2017-10-16  2:32 ` Jérémy Lefaure
  (?)
@ 2017-10-16  2:55 ` Patchwork
  -1 siblings, 0 replies; 8+ messages in thread
From: Patchwork @ 2017-10-16  2:55 UTC (permalink / raw)
  To: Jérémy Lefaure; +Cc: intel-gfx

== Series Details ==

Series: drm/i915/gvt: use ARRAY_SIZE
URL   : https://patchwork.freedesktop.org/series/32003/
State : success

== Summary ==

Series 32003v1 drm/i915/gvt: use ARRAY_SIZE
https://patchwork.freedesktop.org/api/1.0/series/32003/revisions/1/mbox/

Test kms_pipe_crc_basic:
        Subgroup suspend-read-crc-pipe-b:
                dmesg-warn -> PASS       (fi-byt-j1900) fdo#101705

fdo#101705 https://bugs.freedesktop.org/show_bug.cgi?id=101705

fi-bdw-5557u     total:289  pass:268  dwarn:0   dfail:0   fail:0   skip:21  time:462s
fi-bdw-gvtdvm    total:289  pass:265  dwarn:0   dfail:0   fail:0   skip:24  time:478s
fi-blb-e6850     total:289  pass:223  dwarn:1   dfail:0   fail:0   skip:65  time:385s
fi-bsw-n3050     total:289  pass:243  dwarn:0   dfail:0   fail:0   skip:46  time:577s
fi-bwr-2160      total:289  pass:183  dwarn:0   dfail:0   fail:0   skip:106 time:285s
fi-bxt-dsi       total:289  pass:259  dwarn:0   dfail:0   fail:0   skip:30  time:536s
fi-bxt-j4205     total:289  pass:260  dwarn:0   dfail:0   fail:0   skip:29  time:528s
fi-byt-j1900     total:289  pass:254  dwarn:0   dfail:0   fail:0   skip:35  time:540s
fi-byt-n2820     total:289  pass:249  dwarn:1   dfail:0   fail:0   skip:39  time:517s
fi-cfl-s         total:289  pass:253  dwarn:4   dfail:0   fail:0   skip:32  time:568s
fi-elk-e7500     total:289  pass:229  dwarn:0   dfail:0   fail:0   skip:60  time:439s
fi-gdg-551       total:289  pass:178  dwarn:1   dfail:0   fail:1   skip:109 time:273s
fi-glk-1         total:289  pass:261  dwarn:0   dfail:0   fail:0   skip:28  time:607s
fi-hsw-4770r     total:289  pass:262  dwarn:0   dfail:0   fail:0   skip:27  time:438s
fi-ilk-650       total:289  pass:228  dwarn:0   dfail:0   fail:0   skip:61  time:468s
fi-ivb-3520m     total:289  pass:260  dwarn:0   dfail:0   fail:0   skip:29  time:510s
fi-ivb-3770      total:289  pass:260  dwarn:0   dfail:0   fail:0   skip:29  time:474s
fi-kbl-7500u     total:289  pass:264  dwarn:1   dfail:0   fail:0   skip:24  time:504s
fi-kbl-7567u     total:289  pass:269  dwarn:0   dfail:0   fail:0   skip:20  time:492s
fi-kbl-r         total:289  pass:262  dwarn:0   dfail:0   fail:0   skip:27  time:604s
fi-pnv-d510      total:289  pass:222  dwarn:1   dfail:0   fail:0   skip:66  time:654s
fi-skl-6260u     total:289  pass:269  dwarn:0   dfail:0   fail:0   skip:20  time:472s
fi-skl-6700hq    total:289  pass:263  dwarn:0   dfail:0   fail:0   skip:26  time:665s
fi-skl-6700k     total:289  pass:265  dwarn:0   dfail:0   fail:0   skip:24  time:544s
fi-skl-6770hq    total:289  pass:269  dwarn:0   dfail:0   fail:0   skip:20  time:579s
fi-skl-gvtdvm    total:289  pass:266  dwarn:0   dfail:0   fail:0   skip:23  time:476s
fi-snb-2520m     total:289  pass:250  dwarn:0   dfail:0   fail:0   skip:39  time:593s
fi-snb-2600      total:289  pass:249  dwarn:0   dfail:0   fail:0   skip:40  time:436s

3d7ee91be487380ef6cad329fafbe424f6885372 drm-tip: 2017y-10m-14d-00h-14m-47s UTC integration manifest
730543a4cbb9 drm/i915/gvt: use ARRAY_SIZE

== Logs ==

For more details see: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_6044/
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

^ permalink raw reply	[flat|nested] 8+ messages in thread

* ✓ Fi.CI.IGT: success for drm/i915/gvt: use ARRAY_SIZE
  2017-10-16  2:32 ` Jérémy Lefaure
  (?)
  (?)
@ 2017-10-16  4:01 ` Patchwork
  -1 siblings, 0 replies; 8+ messages in thread
From: Patchwork @ 2017-10-16  4:01 UTC (permalink / raw)
  To: Jérémy Lefaure; +Cc: intel-gfx

== Series Details ==

Series: drm/i915/gvt: use ARRAY_SIZE
URL   : https://patchwork.freedesktop.org/series/32003/
State : success

== Summary ==

Test kms_setmode:
        Subgroup basic:
                fail       -> PASS       (shard-hsw) fdo#99912
Test kms_plane:
        Subgroup plane-panning-bottom-right-suspend-pipe-C-planes:
                skip       -> PASS       (shard-hsw)
Test kms_frontbuffer_tracking:
        Subgroup fbc-rgb101010-draw-mmap-gtt:
                skip       -> PASS       (shard-hsw)

fdo#99912 https://bugs.freedesktop.org/show_bug.cgi?id=99912

shard-hsw        total:2553 pass:1442 dwarn:0   dfail:0   fail:8   skip:1103 time:9680s

== Logs ==

For more details see: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_6044/shards.html
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] drm/i915/gvt: use ARRAY_SIZE
  2017-10-16  2:32 ` Jérémy Lefaure
                   ` (2 preceding siblings ...)
  (?)
@ 2017-10-16  9:34 ` Jani Nikula
  2017-10-16  9:37   ` Wang, Zhi A
  -1 siblings, 1 reply; 8+ messages in thread
From: Jani Nikula @ 2017-10-16  9:34 UTC (permalink / raw)
  To: Zhenyu Wang, Zhi Wang, Joonas Lahtinen, Rodrigo Vivi
  Cc: Jérémy Lefaure, intel-gfx, intel-gvt-dev


[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

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] drm/i915/gvt: use ARRAY_SIZE
  2017-10-16  9:34 ` [PATCH] " Jani Nikula
@ 2017-10-16  9:37   ` Wang, Zhi A
  0 siblings, 0 replies; 8+ messages in thread
From: Wang, Zhi A @ 2017-10-16  9:37 UTC (permalink / raw)
  To: Jani Nikula, Zhenyu Wang, Joonas Lahtinen, Vivi, Rodrigo
  Cc: Jérémy Lefaure, intel-gfx@lists.freedesktop.org,
	intel-gvt-dev@lists.freedesktop.org

LGTM and Thanks for the patch!

Reviewed-by: Zhi Wang <zhi.a.wang@intel.com>

-----Original Message-----
From: Jani Nikula [mailto:jani.nikula@linux.intel.com] 
Sent: Monday, October 16, 2017 12:35 PM
To: Jérémy Lefaure <jeremy.lefaure@lse.epita.fr>; Zhenyu Wang <zhenyuw@linux.intel.com>; Wang, Zhi A <zhi.a.wang@intel.com>; Joonas Lahtinen <joonas.lahtinen@linux.intel.com>; Vivi, Rodrigo <rodrigo.vivi@intel.com>
Cc: Jérémy Lefaure <jeremy.lefaure@lse.epita.fr>; intel-gvt-dev@lists.freedesktop.org; intel-gfx@lists.freedesktop.org
Subject: Re: [PATCH] drm/i915/gvt: use ARRAY_SIZE


[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

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] drm/i915/gvt: use ARRAY_SIZE
  2017-10-16  2:32 ` Jérémy Lefaure
@ 2017-10-23 16:38   ` Zhi Wang
  -1 siblings, 0 replies; 8+ messages in thread
From: Zhi Wang @ 2017-10-23 16:38 UTC (permalink / raw)
  To: Jérémy Lefaure, Zhenyu Wang, Jani Nikula,
	Joonas Lahtinen, Rodrigo Vivi, David Airlie
  Cc: intel-gfx, intel-gvt-dev, linux-kernel, dri-devel

Thanks, applied!

On 10/16/17 10:32, Jérémy Lefaure 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.
> 
> 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;
>   
> 
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] drm/i915/gvt: use ARRAY_SIZE
@ 2017-10-23 16:38   ` Zhi Wang
  0 siblings, 0 replies; 8+ messages in thread
From: Zhi Wang @ 2017-10-23 16:38 UTC (permalink / raw)
  To: Jérémy Lefaure, Zhenyu Wang, Jani Nikula,
	Joonas Lahtinen, Rodrigo Vivi, David Airlie
  Cc: intel-gvt-dev, intel-gfx, dri-devel, linux-kernel

Thanks, applied!

On 10/16/17 10:32, Jérémy Lefaure 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.
> 
> 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;
>   
> 

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2017-10-23 16:38 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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 ` [PATCH] " Jani Nikula
2017-10-16  9:37   ` Wang, Zhi A
2017-10-23 16:38 ` Zhi Wang
2017-10-23 16:38   ` Zhi Wang

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.