lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite for Android: free password hash cracker in your pocket
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <c4cc1bd62e52419eb00631e539a6e703@AcuMS.aculab.com>
Date:   Tue, 20 Oct 2020 21:53:04 +0000
From:   David Laight <David.Laight@...LAB.COM>
To:     'Dafna Hirschfeld' <dafna.hirschfeld@...labora.com>,
        'Colin King' <colin.king@...onical.com>,
        Helen Koike <helen.koike@...labora.com>,
        "Mauro Carvalho Chehab" <mchehab@...nel.org>,
        Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
        "linux-media@...r.kernel.org" <linux-media@...r.kernel.org>,
        "devel@...verdev.osuosl.org" <devel@...verdev.osuosl.org>
CC:     "kernel-janitors@...r.kernel.org" <kernel-janitors@...r.kernel.org>,
        "linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>
Subject: RE: [PATCH] media: staging: rkisp1: rsz: make const array static,
 makes object smaller

From: Dafna Hirschfeld
> Sent: 20 October 2020 18:10
> 
> Am 20.10.20 um 17:29 schrieb David Laight:
> > From: Colin King
> >> Sent: 20 October 2020 15:47
> >>
> >> From: Colin Ian King <colin.king@...onical.com>
> >>
...
> >> diff --git a/drivers/staging/media/rkisp1/rkisp1-resizer.c b/drivers/staging/media/rkisp1/rkisp1-
> >> resizer.c
> >> index 1687d82e6c68..7ca5b47c5bf5 100644
> >> --- a/drivers/staging/media/rkisp1/rkisp1-resizer.c
> >> +++ b/drivers/staging/media/rkisp1/rkisp1-resizer.c
> >> @@ -763,8 +763,10 @@ static void rkisp1_rsz_unregister(struct rkisp1_resizer *rsz)
> >>
> >>   static int rkisp1_rsz_register(struct rkisp1_resizer *rsz)
> >>   {
> >> -	const char * const dev_names[] = {RKISP1_RSZ_MP_DEV_NAME,
> >> -					  RKISP1_RSZ_SP_DEV_NAME};
> >> +	static const char * const dev_names[] = {
> >> +		RKISP1_RSZ_MP_DEV_NAME,
> >> +		RKISP1_RSZ_SP_DEV_NAME
> >> +	};
> >>   	struct media_pad *pads = rsz->pads;
> >>   	struct v4l2_subdev *sd = &rsz->sd;
> >>   	int ret;
> >
> > Don't look at what that code is actually doing....
> > It is rather horrid.
> > rkisp1_rsz_register() is called for each entry in an array (twice).
> > The array index is written into rsz->id.
> > The value is then used to select one of the two strings.
> > But rsz->id is actually an enum type.
> 
> Hi,
> Is it that bad to use enum as an array index?
> we use it in many places in the driver.

You'd normally use a constant from the enum to size the array definition.
In this case you've an enum, an array [2] and the dev_names[]
all of which have to match 'by magic'.

There is a loop that half implies you might add a third type.
but then the following code only works for the two types.
You've complex error recovery in case one of the calls to 
rkisp1_rsz_register() fails - but since there can only ever
be two calls the code could be much simpler.

	David

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ