From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752294AbcELJs6 (ORCPT ); Thu, 12 May 2016 05:48:58 -0400 Received: from mailapp01.imgtec.com ([195.59.15.196]:8602 "EHLO mailapp01.imgtec.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751395AbcELJs5 (ORCPT ); Thu, 12 May 2016 05:48:57 -0400 Date: Thu, 12 May 2016 10:49:36 +0100 From: Eric Engestrom To: Muhammad Falak R Wani CC: Christian Knig , Nils =?utf-8?Q?Wallm=C3=A9nius?= , Jammy Zhou , , , Alex Deucher , Rex Zhu , Dan Carpenter Subject: Re: [PATCH] drm/amd/powerplay: use ARRAY_SIZE() for size of array Message-ID: <20160512094936.GO7910@imgtec.com> References: <1462988936-13486-1-git-send-email-falakreyaz@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Disposition: inline In-Reply-To: <1462988936-13486-1-git-send-email-falakreyaz@gmail.com> User-Agent: Mutt/1.5.21 (2010-09-15) X-Originating-IP: [10.60.4.28] Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, May 11, 2016 at 11:18:43PM +0530, Muhammad Falak R Wani wrote: > Use ARRAY_SIZE() for the size calculation of the array. Also move the > condition evaulation function out of the for loop. > Although, any respectable c-compiler would optimize this and evaluate > the function only once outside the loop, but the optimzation engine > of gcc is bit brain-dead, and at times needs some hand holding. `sizeof` is actually a compile-time thing, so at worst, if no optimisation is made, the runtime result is a division of two literals, eg. `for (i = 0; i < 64/8; i++)` (which I doubt any compiler would leave as is anyway) So, +1 on using ARRAY_SIZE, -1 on creating a new variable (which is not even `const` btw) > > Signed-off-by: Muhammad Falak R Wani > --- > drivers/gpu/drm/amd/powerplay/smumgr/cz_smumgr.c | 3 ++- > 1 file changed, 2 insertions(+), 1 deletion(-) > > diff --git a/drivers/gpu/drm/amd/powerplay/smumgr/cz_smumgr.c b/drivers/gpu/drm/amd/powerplay/smumgr/cz_smumgr.c > index da18f44..718a551 100644 > --- a/drivers/gpu/drm/amd/powerplay/smumgr/cz_smumgr.c > +++ b/drivers/gpu/drm/amd/powerplay/smumgr/cz_smumgr.c > @@ -636,10 +636,11 @@ static int cz_smu_populate_firmware_entries(struct pp_smumgr *smumgr) > int ret; > enum cgs_ucode_id ucode_id; > struct cgs_firmware_info info = {0}; > + int n = ARRAY_SIZE(firmware_list); > > cz_smu->driver_buffer_length = 0; > > - for (i = 0; i < sizeof(firmware_list)/sizeof(*firmware_list); i++) { > + for (i = 0; i < n; i++) { > > firmware_type = cz_translate_firmware_enum_to_arg(smumgr, > firmware_list[i]); > -- > 1.9.1 > > _______________________________________________ > dri-devel mailing list > dri-devel@lists.freedesktop.org > https://lists.freedesktop.org/mailman/listinfo/dri-devel