* [PATCH] drm/i915/gvt: Use ARRAY_SIZE macro @ 2018-06-18 7:48 rajan.vaja 2018-06-18 16:20 ` Joe Perches 0 siblings, 1 reply; 3+ messages in thread From: rajan.vaja @ 2018-06-18 7:48 UTC (permalink / raw) To: zhenyuw, zhi.a.wang, jani.nikula, joonas.lahtinen, rodrigo.vivi, airlied Cc: intel-gvt-dev, dri-devel, linux-kernel, Rajan Vaja From: Rajan Vaja <rajan.vaja@gmail.com> Use ARRAY_SIZE instead of dividing sizeof array with sizeof an element. This fixes below warning reported by Coccinelle: drivers/gpu/drm//i915/gvt/vgpu.c:122:30-31: WARNING: Use ARRAY_SIZE Signed-off-by: Rajan Vaja <rajan.vaja@gmail.com> --- drivers/gpu/drm/i915/gvt/vgpu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/gpu/drm/i915/gvt/vgpu.c b/drivers/gpu/drm/i915/gvt/vgpu.c index 2e0a02a..e4c3368 100644 --- a/drivers/gpu/drm/i915/gvt/vgpu.c +++ b/drivers/gpu/drm/i915/gvt/vgpu.c @@ -119,7 +119,7 @@ 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]); + num_types = ARRAY_SIZE(vgpu_types); gvt->types = kzalloc(num_types * sizeof(struct intel_vgpu_type), GFP_KERNEL); -- 2.7.4 ^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] drm/i915/gvt: Use ARRAY_SIZE macro 2018-06-18 7:48 [PATCH] drm/i915/gvt: Use ARRAY_SIZE macro rajan.vaja @ 2018-06-18 16:20 ` Joe Perches 0 siblings, 0 replies; 3+ messages in thread From: Joe Perches @ 2018-06-18 16:20 UTC (permalink / raw) To: rajan.vaja, zhenyuw, zhi.a.wang, jani.nikula, joonas.lahtinen, rodrigo.vivi, airlied Cc: intel-gvt-dev, dri-devel, linux-kernel On Mon, 2018-06-18 at 13:18 +0530, rajan.vaja@gmail.com wrote: > Use ARRAY_SIZE instead of dividing sizeof array with sizeof > an element. This fixes below warning reported by Coccinelle: > drivers/gpu/drm//i915/gvt/vgpu.c:122:30-31: WARNING: Use ARRAY_SIZE [] > diff --git a/drivers/gpu/drm/i915/gvt/vgpu.c b/drivers/gpu/drm/i915/gvt/vgpu.c [] > @@ -119,7 +119,7 @@ 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]); > + num_types = ARRAY_SIZE(vgpu_types); > > gvt->types = kzalloc(num_types * sizeof(struct intel_vgpu_type), > GFP_KERNEL); It seems you are not using -next as this alloc has already been changed to kcalloc. It'd be better to get rid of num_types altogether and use ARRAY_SIZE everywhere instead. There are also string overflow possibilities in the function where sprintf should probably use snprintf. Perhaps: ' int intel_gvt_init_vgpu_types(struct intel_gvt *gvt) { unsigned int i, low_avail, high_avail; unsigned int min_low; /* vGPU type name is defined as GVTg_Vx_y which contains * physical GPU generation type (e.g V4 as BDW server, V5 as * SKL server). * * Depend on physical SKU resource, might see vGPU types like * GVTg_V4_8, GVTg_V4_4, GVTg_V4_2, etc. We can create * different types of vGPU on same physical GPU depending on * available resource. Each vGPU type will have "avail_instance" * to indicate how many vGPU instance can be created for this * type. * */ low_avail = gvt_aperture_sz(gvt) - HOST_LOW_GM_SIZE; high_avail = gvt_hidden_sz(gvt) - HOST_HIGH_GM_SIZE; gvt->types = kcalloc(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 < ARRAY_SIZE(vgpu_types); i++) { if (low_avail / vgpu_types[i].low_mm == 0) break; gvt->types[i].low_gm_size = vgpu_types[i].low_mm; gvt->types[i].high_gm_size = vgpu_types[i].high_mm; gvt->types[i].fence = vgpu_types[i].fence; if (vgpu_types[i].weight < 1 || vgpu_types[i].weight > VGPU_MAX_WEIGHT) return -EINVAL; gvt->types[i].weight = vgpu_types[i].weight; gvt->types[i].resolution = vgpu_types[i].edid; gvt->types[i].avail_instance = min(low_avail / vgpu_types[i].low_mm, high_avail / vgpu_types[i].high_mm); if (IS_GEN8(gvt->dev_priv)) snprintf(gvt->types[i].name, sizeof(gvt->types[i].name), "GVTg_V4_%s", vgpu_types[i].name); else if (IS_GEN9(gvt->dev_priv)) snprintf(gvt->types[i].name, sizeof(gvt->types[i].name), "GVTg_V5_%s", vgpu_types[i].name); gvt_dbg_core("type[%d]: %s avail %u low %u high %u fence %u weight %u res %s\n", i, gvt->types[i].name, gvt->types[i].avail_instance, gvt->types[i].low_gm_size, gvt->types[i].high_gm_size, gvt->types[i].fence, gvt->types[i].weight, vgpu_edid_str(gvt->types[i].resolution)); } gvt->num_types = i; return 0; } ^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] drm/i915/gvt: Use ARRAY_SIZE macro @ 2018-06-18 16:20 ` Joe Perches 0 siblings, 0 replies; 3+ messages in thread From: Joe Perches @ 2018-06-18 16:20 UTC (permalink / raw) To: rajan.vaja, zhenyuw, zhi.a.wang, jani.nikula, joonas.lahtinen, rodrigo.vivi, airlied Cc: intel-gvt-dev, linux-kernel, dri-devel On Mon, 2018-06-18 at 13:18 +0530, rajan.vaja@gmail.com wrote: > Use ARRAY_SIZE instead of dividing sizeof array with sizeof > an element. This fixes below warning reported by Coccinelle: > drivers/gpu/drm//i915/gvt/vgpu.c:122:30-31: WARNING: Use ARRAY_SIZE [] > diff --git a/drivers/gpu/drm/i915/gvt/vgpu.c b/drivers/gpu/drm/i915/gvt/vgpu.c [] > @@ -119,7 +119,7 @@ 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]); > + num_types = ARRAY_SIZE(vgpu_types); > > gvt->types = kzalloc(num_types * sizeof(struct intel_vgpu_type), > GFP_KERNEL); It seems you are not using -next as this alloc has already been changed to kcalloc. It'd be better to get rid of num_types altogether and use ARRAY_SIZE everywhere instead. There are also string overflow possibilities in the function where sprintf should probably use snprintf. Perhaps: ' int intel_gvt_init_vgpu_types(struct intel_gvt *gvt) { unsigned int i, low_avail, high_avail; unsigned int min_low; /* vGPU type name is defined as GVTg_Vx_y which contains * physical GPU generation type (e.g V4 as BDW server, V5 as * SKL server). * * Depend on physical SKU resource, might see vGPU types like * GVTg_V4_8, GVTg_V4_4, GVTg_V4_2, etc. We can create * different types of vGPU on same physical GPU depending on * available resource. Each vGPU type will have "avail_instance" * to indicate how many vGPU instance can be created for this * type. * */ low_avail = gvt_aperture_sz(gvt) - HOST_LOW_GM_SIZE; high_avail = gvt_hidden_sz(gvt) - HOST_HIGH_GM_SIZE; gvt->types = kcalloc(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 < ARRAY_SIZE(vgpu_types); i++) { if (low_avail / vgpu_types[i].low_mm == 0) break; gvt->types[i].low_gm_size = vgpu_types[i].low_mm; gvt->types[i].high_gm_size = vgpu_types[i].high_mm; gvt->types[i].fence = vgpu_types[i].fence; if (vgpu_types[i].weight < 1 || vgpu_types[i].weight > VGPU_MAX_WEIGHT) return -EINVAL; gvt->types[i].weight = vgpu_types[i].weight; gvt->types[i].resolution = vgpu_types[i].edid; gvt->types[i].avail_instance = min(low_avail / vgpu_types[i].low_mm, high_avail / vgpu_types[i].high_mm); if (IS_GEN8(gvt->dev_priv)) snprintf(gvt->types[i].name, sizeof(gvt->types[i].name), "GVTg_V4_%s", vgpu_types[i].name); else if (IS_GEN9(gvt->dev_priv)) snprintf(gvt->types[i].name, sizeof(gvt->types[i].name), "GVTg_V5_%s", vgpu_types[i].name); gvt_dbg_core("type[%d]: %s avail %u low %u high %u fence %u weight %u res %s\n", i, gvt->types[i].name, gvt->types[i].avail_instance, gvt->types[i].low_gm_size, gvt->types[i].high_gm_size, gvt->types[i].fence, gvt->types[i].weight, vgpu_edid_str(gvt->types[i].resolution)); } gvt->num_types = i; return 0; } _______________________________________________ dri-devel mailing list dri-devel@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/dri-devel ^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2018-06-18 16:20 UTC | newest] Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2018-06-18 7:48 [PATCH] drm/i915/gvt: Use ARRAY_SIZE macro rajan.vaja 2018-06-18 16:20 ` Joe Perches 2018-06-18 16:20 ` Joe Perches
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.