All of lore.kernel.org
 help / color / mirror / Atom feed
From: Dan Carpenter <dan.carpenter@oracle.com>
To: Tony Cho <tony.cho@atmel.com>
Cc: gregkh@linuxfoundation.org, devel@driverdev.osuosl.org,
	rachel.kim@atmel.com, chris.park@atmel.com,
	linux-wireless@vger.kernel.org, johnny.kim@atmel.com,
	jude.lee@atmel.com, leo.kim@atmel.com
Subject: Re: [PATCH 5/5] staging: wilc1000: use id value as argument
Date: Thu, 13 Aug 2015 17:49:07 +0300	[thread overview]
Message-ID: <20150813144907.GA4484@mwanda> (raw)
In-Reply-To: <1439440883-16061-6-git-send-email-tony.cho@atmel.com>

On Thu, Aug 13, 2015 at 01:41:23PM +0900, Tony Cho wrote:
> +static u32 get_id_from_handler(tstrWILC_WFIDrv *handler)
> +{
> +	u32 id;
> +
> +	if (!handler)
> +		return 0;
> +
> +	for (id = 0; id < NUM_CONCURRENT_IFC; id++) {
> +		if (wfidrv_list[id] == handler) {
> +			id += 1;
> +			break;
> +		}
> +	}
> +
> +	if (id > NUM_CONCURRENT_IFC)
> +		return 0;
> +	else
> +		return id;
> +}
> +

This still has an off by one bug.  Just use zero offset arrays
throughout.

static int get_id_from_handler(tstrWILC_WFIDrv *handler)
{
	int id;

	if (!handler)
		return -ENOBUFS;

	for (id = 0; id < NUM_CONCURRENT_IFC; id++) {
		if (wfidrv_list[id] == handler)
			return id;
	}

	return -ENOBUFS;
}

> +static tstrWILC_WFIDrv *get_handler_from_id(u32 id)
> +{
> +	if (id > 0 && id <= NUM_CONCURRENT_IFC)
> +		return wfidrv_list[id - 1];
> +	else
> +		return NULL;
> +}

static tstrWILC_WFIDrv *get_handler_from_id(int id)
{
	if (id < 0 || id >= NUM_CONCURRENT_IFC)
		return NULL;
	return wfidrv_list[id];
}

regards,
dan carpenter


  reply	other threads:[~2015-08-13 14:49 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-08-13  4:41 [PATCH 0/5] staging: wilc1000: 64bit build patch Tony Cho
2015-08-13  4:41 ` [PATCH 1/5] staging: wilc1000: replace WILC_WFIDrvHandle by tstrWILC_WFIDrv Tony Cho
2015-08-13  4:41 ` [PATCH 2/5] staging: wilc1000: change void pointer type to real type Tony Cho
2015-08-14  6:26   ` Sudip Mukherjee
2015-08-15  2:01     ` Greg KH
2015-08-13  4:41 ` [PATCH 3/5] staging: wilc1000: clarify the argument type Tony Cho
2015-08-13  4:41 ` [PATCH 4/5] staging: wilc1000: use the real data type Tony Cho
2015-08-15  2:04   ` Greg KH
2015-08-13  4:41 ` [PATCH 5/5] staging: wilc1000: use id value as argument Tony Cho
2015-08-13 14:49   ` Dan Carpenter [this message]
2015-08-18  3:10     ` Johnny Kim
2015-08-18  9:12       ` Dan Carpenter
2015-08-19  7:58         ` Johnny Kim
2015-08-19 10:05           ` Dan Carpenter
  -- strict thread matches above, loose matches on Subject: below --
2015-08-10  5:58 [PATCH 0/5] 64 bit build patch Tony Cho
2015-08-10  5:58 ` [PATCH 5/5] staging: wilc1000: use id value as argument Tony Cho
2015-08-10  6:47   ` Julian Calaby
2015-08-10  7:53     ` Johnny Kim
2015-08-10 10:44   ` Dan Carpenter

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=20150813144907.GA4484@mwanda \
    --to=dan.carpenter@oracle.com \
    --cc=chris.park@atmel.com \
    --cc=devel@driverdev.osuosl.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=johnny.kim@atmel.com \
    --cc=jude.lee@atmel.com \
    --cc=leo.kim@atmel.com \
    --cc=linux-wireless@vger.kernel.org \
    --cc=rachel.kim@atmel.com \
    --cc=tony.cho@atmel.com \
    /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.