netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Andy Shevchenko <andriy.shevchenko-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
To: Heikki Krogerus
	<heikki.krogerus-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>,
	Johannes Berg <johannes-cdvu00un1VgdHxzADdlk8Q@public.gmane.org>
Cc: "Rafael J. Wysocki" <rjw-LthD3rsA81gm4RdzfppkhA@public.gmane.org>,
	Mika Westerberg
	<mika.westerberg-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>,
	linux-wireless-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	netdev-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	linux-tegra-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Subject: Re: [PATCH 2/5] net: rfkill: add rfkill_find_type function
Date: Wed, 05 Aug 2015 17:07:29 +0300	[thread overview]
Message-ID: <1438783649.29746.175.camel@linux.intel.com> (raw)
In-Reply-To: <1438781947-7952-3-git-send-email-heikki.krogerus-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>

On Wed, 2015-08-05 at 16:39 +0300, Heikki Krogerus wrote:
> Helper for finding the type based on name. Useful if the
> type needs to be determined based on device property.
> 
> Signed-off-by: Heikki Krogerus <heikki.krogerus-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
> ---
>  include/linux/rfkill.h | 15 +++++++++++++
>  net/rfkill/core.c      | 57 +++++++++++++++++++++++++---------------
> ----------
>  2 files changed, 44 insertions(+), 28 deletions(-)
> 
> diff --git a/include/linux/rfkill.h b/include/linux/rfkill.h
> index d901078..02f563c 100644
> --- a/include/linux/rfkill.h
> +++ b/include/linux/rfkill.h
> @@ -212,6 +212,15 @@ void rfkill_set_states(struct rfkill *rfkill, 
> bool sw, bool hw);
>   * @rfkill: rfkill struct to query
>   */
>  bool rfkill_blocked(struct rfkill *rfkill);
> +
> +/**
> + * rfkill_find_type - Helpper for finding rfkill type by name
> + * @name: the name of the type
> + *
> + * Returns enum rfkill_type that conrresponds the name.
> + */
> +enum rfkill_type rfkill_find_type(const char *name);
> +
>  #else /* !RFKILL */
>  static inline struct rfkill * __must_check
>  rfkill_alloc(const char *name,
> @@ -268,6 +277,12 @@ static inline bool rfkill_blocked(struct rfkill 
> *rfkill)
>  {
>  	return false;
>  }
> +
> +static inline enum rfkill_type rfkill_find_type(const char *name)
> +{
> +	return 0;

Hmm… Besides 0 is implicitly casted to enum type the issue with enums
that you rather have to supply existing enum entry. I would suggest to
add RFKILL_TYPE_UNKNOWN if _ALL is reserved for some use cases.

> +}
> +
>  #endif /* RFKILL || RFKILL_MODULE */
>  
>  
> diff --git a/net/rfkill/core.c b/net/rfkill/core.c
> index f12149a..53d7a97e 100644
> --- a/net/rfkill/core.c
> +++ b/net/rfkill/core.c
> @@ -574,6 +574,33 @@ void rfkill_set_states(struct rfkill *rfkill, 
> bool sw, bool hw)
>  }
>  EXPORT_SYMBOL(rfkill_set_states);
>  
> +static const char *rfkill_types[NUM_RFKILL_TYPES] = {
> +	[RFKILL_TYPE_WLAN]	= "wlan",
> +	[RFKILL_TYPE_BLUETOOTH]	= "bluetooth",
> +	[RFKILL_TYPE_UWB]	= "ultrawideband",
> +	[RFKILL_TYPE_WIMAX]	= "wimax",
> +	[RFKILL_TYPE_WWAN]	= "wwan",
> +	[RFKILL_TYPE_GPS]	= "gps",
> +	[RFKILL_TYPE_FM]	= "fm",
> +	[RFKILL_TYPE_NFC]	= "nfc",
> +};
> +
> +enum rfkill_type rfkill_find_type(const char *name)
> +{
> +	int i;
> +
> +	BUILD_BUG_ON(NUM_RFKILL_TYPES != RFKILL_TYPE_NFC + 1);
> +
> +	if (!name)
> +		return RFKILL_TYPE_ALL;
> +
> +	for (i = 1; i < NUM_RFKILL_TYPES; i++)
> +		if (!strcmp(name, rfkill_types[i]))
> +			return i;
> +	return RFKILL_TYPE_ALL;
> +}
> +EXPORT_SYMBOL(rfkill_find_type);
> +
>  static ssize_t name_show(struct device *dev, struct device_attribute 
> *attr,
>  			 char *buf)
>  {
> @@ -583,38 +610,12 @@ static ssize_t name_show(struct device *dev, 
> struct device_attribute *attr,
>  }
>  static DEVICE_ATTR_RO(name);
>  
> -static const char *rfkill_get_type_str(enum rfkill_type type)
> -{
> -	BUILD_BUG_ON(NUM_RFKILL_TYPES != RFKILL_TYPE_NFC + 1);
> -
> -	switch (type) {
> -	case RFKILL_TYPE_WLAN:
> -		return "wlan";
> -	case RFKILL_TYPE_BLUETOOTH:
> -		return "bluetooth";
> -	case RFKILL_TYPE_UWB:
> -		return "ultrawideband";
> -	case RFKILL_TYPE_WIMAX:
> -		return "wimax";
> -	case RFKILL_TYPE_WWAN:
> -		return "wwan";
> -	case RFKILL_TYPE_GPS:
> -		return "gps";
> -	case RFKILL_TYPE_FM:
> -		return "fm";
> -	case RFKILL_TYPE_NFC:
> -		return "nfc";
> -	default:
> -		BUG();
> -	}
> -}
> -
>  static ssize_t type_show(struct device *dev, struct device_attribute 
> *attr,
>  			 char *buf)
>  {
>  	struct rfkill *rfkill = to_rfkill(dev);
>  
> -	return sprintf(buf, "%s\n", rfkill_get_type_str(rfkill
> ->type));
> +	return sprintf(buf, "%s\n", rfkill_types[rfkill->type]);
>  }
>  static DEVICE_ATTR_RO(type);
>  
> @@ -760,7 +761,7 @@ static int rfkill_dev_uevent(struct device *dev, 
> struct kobj_uevent_env *env)
>  	if (error)
>  		return error;
>  	error = add_uevent_var(env, "RFKILL_TYPE=%s",
> -			       rfkill_get_type_str(rfkill->type));
> +			       rfkill_types[rfkill->type]);
>  	if (error)
>  		return error;
>  	spin_lock_irqsave(&rfkill->lock, flags);

-- 
Andy Shevchenko <andriy.shevchenko-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
Intel Finland Oy

  parent reply	other threads:[~2015-08-05 14:07 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-08-05 13:39 [PATCH 0/5] net: rfkill: gpio: replace platform data with build-in property Heikki Krogerus
2015-08-05 13:39 ` [PATCH 1/5] device property: helper macros for property entry creation Heikki Krogerus
2015-08-05 14:02   ` Andy Shevchenko
2015-08-05 14:12     ` Shevchenko, Andriy
2015-08-06  7:48     ` Heikki Krogerus
     [not found]       ` <20150806074848.GH7675-FZxXFokcWpatqXYlAKuG4QC/G2K4zDHf@public.gmane.org>
2015-08-07 22:08         ` Rafael J. Wysocki
2015-08-05 13:39 ` [PATCH 2/5] net: rfkill: add rfkill_find_type function Heikki Krogerus
     [not found]   ` <1438781947-7952-3-git-send-email-heikki.krogerus-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
2015-08-05 14:07     ` Andy Shevchenko [this message]
2015-08-06  8:30       ` Heikki Krogerus
     [not found]         ` <20150806083004.GI7675-FZxXFokcWpatqXYlAKuG4QC/G2K4zDHf@public.gmane.org>
2015-08-06  9:26           ` Andy Shevchenko
2015-08-06 11:31   ` Sergei Shtylyov
2015-08-13  9:27   ` Johannes Berg
2015-08-13 12:37     ` Heikki Krogerus
2015-08-05 13:39 ` [PATCH 3/5] net: rfkill: gpio: get the name and type from device property Heikki Krogerus
2015-08-05 13:39 ` [PATCH 4/5] ARM: tegra: use build-in device properties with rfkill_gpio Heikki Krogerus
     [not found] ` <1438781947-7952-1-git-send-email-heikki.krogerus-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
2015-08-05 13:39   ` [PATCH 5/5] net: rfkill: gpio: remove rfkill_gpio_platform_data Heikki Krogerus
     [not found]     ` <1438781947-7952-6-git-send-email-heikki.krogerus-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
2015-08-05 14:15       ` Andy Shevchenko
     [not found]         ` <1438784128.29746.177.camel-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
2015-08-06  7:22           ` Heikki Krogerus

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=1438783649.29746.175.camel@linux.intel.com \
    --to=andriy.shevchenko-vuqaysv1563yd54fqh9/ca@public.gmane.org \
    --cc=heikki.krogerus-VuQAYsv1563Yd54FQh9/CA@public.gmane.org \
    --cc=johannes-cdvu00un1VgdHxzADdlk8Q@public.gmane.org \
    --cc=linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=linux-tegra-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=linux-wireless-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=mika.westerberg-VuQAYsv1563Yd54FQh9/CA@public.gmane.org \
    --cc=netdev-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=rjw-LthD3rsA81gm4RdzfppkhA@public.gmane.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 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).