From: Ingo Oeser <netdev@axxeo.de>
To: "John W. Linville" <linville@tuxdriver.com>
Cc: davem@davemloft.net, linux-wireless@vger.kernel.org,
netdev@vger.kernel.org, johannes@sipsolutions.net
Subject: Re: [PATCH] cfg80211: new wireless config infrastructure
Date: Wed, 25 Apr 2007 18:06:45 +0200 [thread overview]
Message-ID: <200704251806.46270.netdev@axxeo.de> (raw)
In-Reply-To: <20070423183634.GE5883@tuxdriver.com>
Hi there,
John W. Linville schrieb:
> From: Johannes Berg <johannes@sipsolutions.net>
> --- /dev/null
> +++ b/net/wireless/core.c
> @@ -0,0 +1,209 @@
> +/*
> + * This is the linux wireless configuration interface.
> + *
> + * Copyright 2006, 2007 Johannes Berg <johannes@sipsolutions.net>
> + */
> +
> +#include <linux/if.h>
> +#include <linux/module.h>
> +#include <linux/err.h>
> +#include <linux/mutex.h>
> +#include <linux/list.h>
> +#include <linux/nl80211.h>
> +#include <linux/debugfs.h>
> +#include <linux/notifier.h>
> +#include <linux/device.h>
> +#include <net/genetlink.h>
> +#include <net/cfg80211.h>
> +#include <net/wireless.h>
> +#include "core.h"
> +#include "sysfs.h"
> +
> +/* name for sysfs, %d is appended */
> +#define PHY_NAME "phy"
> +
> +MODULE_AUTHOR("Johannes Berg");
> +MODULE_LICENSE("GPL");
> +MODULE_DESCRIPTION("wireless configuration support");
> +
> +/* RCU might be appropriate here since we usually
> + * only read the list, and that can happen quite
> + * often because we need to do it for each command */
> +LIST_HEAD(cfg80211_drv_list);
> +DEFINE_MUTEX(cfg80211_drv_mutex);
> +static int wiphy_counter;
> +
> +/* for debugfs */
> +static struct dentry *ieee80211_debugfs_dir;
> +
> +/* exported functions */
> +
> +struct wiphy *wiphy_new(struct cfg80211_ops *ops, int sizeof_priv)
> +{
> + struct cfg80211_registered_device *drv;
> + int alloc_size;
> +
> + alloc_size = sizeof(*drv) + sizeof_priv;
> +
> + drv = kzalloc(alloc_size, GFP_KERNEL);
> + if (!drv)
> + return NULL;
> +
> + drv->ops = ops;
> +
> + mutex_lock(&cfg80211_drv_mutex);
> +
> + if (unlikely(wiphy_counter<0)) {
mutex_unlock(&cfg80211_drv_mutex);
> + /* ugh, wrapped! */
> + kfree(drv);
> + return NULL;
> + }
> + drv->idx = wiphy_counter;
> +
> + /* give it a proper name */
> + snprintf(drv->wiphy.dev.bus_id, BUS_ID_SIZE,
> + PHY_NAME "%d", drv->idx);
> +
> + /* now increase counter for the next time */
> + wiphy_counter++;
> + mutex_unlock(&cfg80211_drv_mutex);
Since drv and its contents are not visible to anyone yet,
I suggest the following code flow for that:
mutex_lock(&cfg80211_drv_mutex);
drv->idx = wiphy_counter;
/* increase counter for the next time, if id didn't wrap */
if (drv->idx >= 0)
wiphy_counter++;
mutex_unlock(&cfg80211_drv_mutex);
if (drv->idx < 0) {
kfree(drv);
return NULL;
}
/* give it a proper name */
snprintf(drv->wiphy.dev.bus_id, BUS_ID_SIZE,
PHY_NAME "%d", drv->idx);
[enqueue to all lists here]
Rest looks good so far.
Regards
Ingo Oeser
next prev parent reply other threads:[~2007-04-25 16:07 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-04-23 18:33 [PATCH] update MAINTAINERS for wireless mailing list John W. Linville
[not found] ` <20070423183334.GC5883-2XuSBdqkA4R54TAoqtyWWQ@public.gmane.org>
2007-04-23 18:34 ` [PATCH] refactor wireless Kconfig John W. Linville
[not found] ` <20070423183443.GD5883-2XuSBdqkA4R54TAoqtyWWQ@public.gmane.org>
2007-04-23 18:36 ` [PATCH] cfg80211: new wireless config infrastructure John W. Linville
[not found] ` <20070423183634.GE5883-2XuSBdqkA4R54TAoqtyWWQ@public.gmane.org>
2007-04-23 18:37 ` [PATCH] remove wext over netlink John W. Linville
2007-04-24 9:22 ` [PATCH] cfg80211: update comment for locking Johannes Berg
2007-04-25 16:06 ` Ingo Oeser [this message]
2007-04-26 13:14 ` [PATCH wireless-dev, net-2.6.22] cfg80211: fix locking in wiphy_new Johannes Berg
2007-04-23 19:35 ` [PATCH] refactor wireless Kconfig Stefano Brivio
2007-04-23 19:53 ` [PATCH] drivers/net/wireless/Kconfig: correct minor typo John W. Linville
[not found] ` <20070423195313.GG5883-2XuSBdqkA4R54TAoqtyWWQ@public.gmane.org>
2007-04-23 20:29 ` David Miller
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=200704251806.46270.netdev@axxeo.de \
--to=netdev@axxeo.de \
--cc=davem@davemloft.net \
--cc=johannes@sipsolutions.net \
--cc=linux-wireless@vger.kernel.org \
--cc=linville@tuxdriver.com \
--cc=netdev@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 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).