All of lore.kernel.org
 help / color / mirror / Atom feed
From: Ian Abbott <abbotti@mev.co.uk>
To: kernel-janitors@vger.kernel.org
Subject: Re: [patch] staging: comedi: cleanup comedi_recognize()
Date: Thu, 24 May 2012 11:17:37 +0000	[thread overview]
Message-ID: <4FBE18D1.8060405@mev.co.uk> (raw)
In-Reply-To: <20120524102851.GA4399@elgon.mountain>

On 2012-05-24 12:16, Dan Carpenter wrote:
> On Thu, May 24, 2012 at 11:57:44AM +0100, Ian Abbott wrote:
>> On 2012-05-24 11:28, Dan Carpenter wrote:
>>> This function is more complicated than it needs to be because of the
>>> consts.  It's not worth saving them because we drop the consts anyway
>>> when we return (void *)name_ptr.
>>>
>>> Signed-off-by: Dan Carpenter<dan.carpenter@oracle.com>
>>>
>>> diff --git a/drivers/staging/comedi/drivers.c b/drivers/staging/comedi/drivers.c
>>> index 1c3d638..a8f576d 100644
>>> --- a/drivers/staging/comedi/drivers.c
>>> +++ b/drivers/staging/comedi/drivers.c
>>> @@ -304,14 +304,13 @@ static int postconfig(struct comedi_device *dev)
>>>    * that register their supported board names */
>>>   static void *comedi_recognize(struct comedi_driver *driv, const char *name)
>>>   {
>>> -	unsigned i;
>>> -	const char *const *name_ptr = driv->board_name;
>>> +	char **name_ptr = (char **)driv->board_name;
>>> +	int i;
>>> +
>>>   	for (i = 0; i<   driv->num_names; i++) {
>>>   		if (strcmp(*name_ptr, name) = 0)
>>> -			return (void *)name_ptr;
>>> -		name_ptr >>> -		    (const char *const *)((const char *)name_ptr +
>>> -					  driv->offset);
>>> +			return name_ptr;
>>> +		name_ptr = (char **)((void *)name_ptr + driv->offset);
>>>   	}
>>>
>>>   	return NULL;
>>
>> You could simplify it further by keeping one of the consts:
>>
>> static void *comedi_recognize(struct comedi_driver *driv, const char *name)
>> {
>> 	unsigned i;
>> 	const char **name_ptr = driv->board_name;
>> 	for (i = 0; i<  driv->num_names; i++) {
>> 		if (strcmp(*name_ptr, name) = 0)
>> 			return name_ptr;
>> 		name_ptr = (void *)name_ptr + driv->offset;
>> 	}
>> 	return NULL;
>> }
>
> Sure.  I'll resend.

Actually, my version gives a warning about a dropped qualifier, so the 
initializer of name_ptr would need a cast after all.  You could keep 
your version but remove the casts from (void *) when converting to the 
other pointer types.

static void *comedi_recognize(struct comedi_driver *driv, const char *name)
{
	unsigned i;
	char **name_ptr = (char **)driv->board_name;
	for (i = 0; i < driv->num_names; i++) {
		if (strcmp(*name_ptr, name) = 0)
			return name_ptr;
		name_ptr = (void *)name_ptr + driv->offset;
	}

	return NULL;
}

-- 
-=( Ian Abbott @ MEV Ltd.    E-mail: <abbotti@mev.co.uk>        )=-
-=( Tel: +44 (0)161 477 1898   FAX: +44 (0)161 718 3587         )=-

  parent reply	other threads:[~2012-05-24 11:17 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-05-24 10:28 [patch] staging: comedi: cleanup comedi_recognize() Dan Carpenter
2012-05-24 10:57 ` Ian Abbott
2012-05-24 11:16 ` Dan Carpenter
2012-05-24 11:17 ` Ian Abbott [this message]
2012-06-05 10:06 ` walter harms
2012-06-05 11:01 ` Dan Carpenter
2012-06-06  9:28 ` Ian Abbott
2012-06-06  9:45 ` walter harms
2012-06-06  9:49 ` Dan Carpenter
2012-06-06 11:20 ` Ian Abbott
2012-06-06 12:28 ` walter harms
2012-06-06 14:11 ` Ian Abbott

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=4FBE18D1.8060405@mev.co.uk \
    --to=abbotti@mev.co.uk \
    --cc=kernel-janitors@vger.kernel.org \
    /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.