linux-wireless.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Ivo van Doorn <ivdoorn@gmail.com>
To: Henrique de Moraes Holschuh <hmh@hmh.eng.br>
Cc: John Linville <linville@tuxdriver.com>,
	linux-wireless@vger.kernel.org,
	Johannes Berg <johannes@sipsolutions.net>
Subject: Re: [PATCH 3/5] rfkill: add WARN and BUG_ON paranoia (v2)
Date: Tue, 26 Aug 2008 17:56:06 +0200	[thread overview]
Message-ID: <200808261756.06759.IvDoorn@gmail.com> (raw)
In-Reply-To: <1219762681-26911-4-git-send-email-hmh@hmh.eng.br>

On Tuesday 26 August 2008, Henrique de Moraes Holschuh wrote:
> BUG_ON() and WARN() the heck out of buggy drivers calling into the rfkill
> subsystem.
> 
> Also switch from WARN_ON(1) to the new descriptive WARN().

The below usage of WARN() were correct when used as WARN_ON(),
(I only complained about the litteral WARN_ON(1) usage.
But apparently the WARN arguments are now the same as WARN_ON(),
so I have no objections against this patch.
 
> Signed-off-by: Henrique de Moraes Holschuh <hmh@hmh.eng.br>
> Cc: Ivo van Doorn <IvDoorn@gmail.com>
> Cc: Johannes Berg <johannes@sipsolutions.net>

Acked-by: Ivo van Doorn <IvDoorn@gmail.com>

> ---
>  net/rfkill/rfkill.c |   50 +++++++++++++++++++++++++++++++++++++-------------
>  1 files changed, 37 insertions(+), 13 deletions(-)
> 
> diff --git a/net/rfkill/rfkill.c b/net/rfkill/rfkill.c
> index b630f35..910699c 100644
> --- a/net/rfkill/rfkill.c
> +++ b/net/rfkill/rfkill.c
> @@ -76,6 +76,7 @@ static BLOCKING_NOTIFIER_HEAD(rfkill_notifier_list);
>   */
>  int register_rfkill_notifier(struct notifier_block *nb)
>  {
> +	BUG_ON(!nb);
>  	return blocking_notifier_chain_register(&rfkill_notifier_list, nb);
>  }
>  EXPORT_SYMBOL_GPL(register_rfkill_notifier);
> @@ -91,6 +92,7 @@ EXPORT_SYMBOL_GPL(register_rfkill_notifier);
>   */
>  int unregister_rfkill_notifier(struct notifier_block *nb)
>  {
> +	BUG_ON(!nb);
>  	return blocking_notifier_chain_unregister(&rfkill_notifier_list, nb);
>  }
>  EXPORT_SYMBOL_GPL(unregister_rfkill_notifier);
> @@ -202,6 +204,9 @@ static int rfkill_toggle_radio(struct rfkill *rfkill,
>  		 * RFKILL_STATE_HARD_BLOCKED */
>  		break;
>  	default:
> +		WARN(1, KERN_WARNING
> +			"rfkill: illegal state %d passed as parameter "
> +			"to rfkill_toggle_radio\n", state);
>  		return -EINVAL;
>  	}
>  
> @@ -236,7 +241,11 @@ static void __rfkill_switch_all(const enum rfkill_type type,
>  {
>  	struct rfkill *rfkill;
>  
> -	if (unlikely(state >= RFKILL_STATE_MAX))
> +	if (WARN((state >= RFKILL_STATE_MAX || type >= RFKILL_TYPE_MAX),
> +			KERN_WARNING
> +			"rfkill: illegal state %d or type %d "
> +			"passed as parameter to __rfkill_switch_all\n",
> +			state, type))
>  		return;
>  
>  	rfkill_global_states[type].current_state = state;
> @@ -334,7 +343,11 @@ int rfkill_force_state(struct rfkill *rfkill, enum rfkill_state state)
>  {
>  	enum rfkill_state oldstate;
>  
> -	if (unlikely(state >= RFKILL_STATE_MAX))
> +	BUG_ON(!rfkill);
> +	if (WARN((state >= RFKILL_STATE_MAX),
> +			KERN_WARNING
> +			"rfkill: illegal state %d passed as parameter "
> +			"to rfkill_force_state\n", state))
>  		return -EINVAL;
>  
>  	mutex_lock(&rfkill->mutex);
> @@ -593,10 +606,10 @@ static int rfkill_check_duplicity(const struct rfkill *rfkill)
>  	memset(seen, 0, sizeof(seen));
>  
>  	list_for_each_entry(p, &rfkill_list, node) {
> -		if (p == rfkill) {
> -			WARN_ON(1);
> +		if (WARN((p == rfkill), KERN_WARNING
> +				"rfkill: illegal attempt to register "
> +				"an already registered rfkill struct\n"))
>  			return -EEXIST;
> -		}
>  		set_bit(p->type, seen);
>  	}
>  
> @@ -664,6 +677,12 @@ struct rfkill * __must_check rfkill_allocate(struct device *parent,
>  	struct rfkill *rfkill;
>  	struct device *dev;
>  
> +	if (WARN((type >= RFKILL_TYPE_MAX),
> +			KERN_WARNING
> +			"rfkill: illegal type %d passed as parameter "
> +			"to rfkill_allocate\n", type))
> +		return NULL;
> +
>  	rfkill = kzalloc(sizeof(struct rfkill), GFP_KERNEL);
>  	if (!rfkill)
>  		return NULL;
> @@ -736,11 +755,12 @@ int __must_check rfkill_register(struct rfkill *rfkill)
>  	struct device *dev = &rfkill->dev;
>  	int error;
>  
> -	if (!rfkill->toggle_radio)
> -		return -EINVAL;
> -	if (rfkill->type >= RFKILL_TYPE_MAX)
> -		return -EINVAL;
> -	if (rfkill->state >= RFKILL_STATE_MAX)
> +	if (WARN((!rfkill || !rfkill->toggle_radio ||
> +			rfkill->type >= RFKILL_TYPE_MAX ||
> +			rfkill->state >= RFKILL_STATE_MAX),
> +			KERN_WARNING
> +			"rfkill: attempt to register a "
> +			"badly initialized rfkill struct\n"))
>  		return -EINVAL;
>  
>  	snprintf(dev->bus_id, sizeof(dev->bus_id),
> @@ -775,6 +795,7 @@ EXPORT_SYMBOL(rfkill_register);
>   */
>  void rfkill_unregister(struct rfkill *rfkill)
>  {
> +	BUG_ON(!rfkill);
>  	device_del(&rfkill->dev);
>  	rfkill_remove_switch(rfkill);
>  	rfkill_led_trigger_unregister(rfkill);
> @@ -811,9 +832,12 @@ int rfkill_set_default(enum rfkill_type type, enum rfkill_state state)
>  {
>  	int error;
>  
> -	if (type >= RFKILL_TYPE_MAX ||
> -	    (state != RFKILL_STATE_SOFT_BLOCKED &&
> -	     state != RFKILL_STATE_UNBLOCKED))
> +	if (WARN((type >= RFKILL_TYPE_MAX ||
> +			(state != RFKILL_STATE_SOFT_BLOCKED &&
> +			 state != RFKILL_STATE_UNBLOCKED)),
> +			KERN_WARNING
> +			"rfkill: illegal state %d or type %d passed as "
> +			"parameter to rfkill_set_default\n", state, type))
>  		return -EINVAL;
>  
>  	mutex_lock(&rfkill_mutex);



  reply	other threads:[~2008-08-26 15:56 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-08-26 14:57 [GIT PATCH] rfkill changes for 2.6.28, set 1a Henrique de Moraes Holschuh
2008-08-26 14:57 ` [PATCH 1/5] rfkill: use strict_strtoul (v2) Henrique de Moraes Holschuh
2008-08-26 14:57 ` [PATCH 2/5] rfkill: add missing line break Henrique de Moraes Holschuh
2008-08-26 14:57 ` [PATCH 3/5] rfkill: add WARN and BUG_ON paranoia (v2) Henrique de Moraes Holschuh
2008-08-26 15:56   ` Ivo van Doorn [this message]
2008-08-26 14:58 ` [PATCH 4/5] rfkill: rename rfkill_mutex to rfkill_global_mutex Henrique de Moraes Holschuh
2008-08-26 14:58 ` [PATCH 5/5] rfkill: remove transmitter blocking on suspend Henrique de Moraes Holschuh
2008-08-26 15:39   ` Greg KH
2008-08-27  4:56     ` Henrique de Moraes Holschuh
2008-08-26 16:13   ` Ivo van Doorn
2008-08-26 19:49     ` Tomas Winkler
2008-08-27 23:01     ` Henrique de Moraes Holschuh
2008-08-28 14:29       ` Ivo van Doorn
2008-08-26 22:56   ` Philip Langdale
2008-09-03 19:05   ` John W. Linville
2008-09-03 21:20     ` Henrique de Moraes Holschuh
2008-09-03 21:31       ` Michael Buesch
2008-09-09 19:22       ` John W. Linville

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=200808261756.06759.IvDoorn@gmail.com \
    --to=ivdoorn@gmail.com \
    --cc=hmh@hmh.eng.br \
    --cc=johannes@sipsolutions.net \
    --cc=linux-wireless@vger.kernel.org \
    --cc=linville@tuxdriver.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).