netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Luciano Coelho <luciano.coelho@nokia.com>
To: ext Patrick McHardy <kaber@trash.net>
Cc: "netfilter@vger.kernel.org" <netfilter@vger.kernel.org>,
	"netdev@vger.kernel.org" <netdev@vger.kernel.org>,
	Jan Engelhardt <jengelh@medozas.de>,
	Timo Teras <timo.teras@iki.fi>
Subject: Re: [PATCH v4] netfilter: Xtables: idletimer target implementation
Date: Mon, 14 Jun 2010 17:59:24 +0300	[thread overview]
Message-ID: <1276527564.2092.42.camel@chilepepper> (raw)
In-Reply-To: <4C164152.8080103@trash.net>

On Mon, 2010-06-14 at 16:48 +0200, ext Patrick McHardy wrote:
> Luciano Coelho wrote:
> > +static int idletimer_tg_create(struct idletimer_tg_info *info)
> > +{
> > +	int ret;
> > +
> > +	info->timer = kmalloc(sizeof(*info->timer), GFP_ATOMIC);
> > +	if (!info->timer) {
> > +		pr_debug("couldn't alloc timer\n");
> > +		ret = -ENOMEM;
> > +		goto out;
> > +	}
> > +
> > +	info->timer->attr.attr.name = kstrdup(info->label, GFP_ATOMIC);
> >   
> 
> These two allocations don't need GFP_ATOMIC AFAICT.

You're right, I'll fix it in v5.


> 
> > +	if (!info->timer->attr.attr.name) {
> > +		pr_debug("couldn't alloc attribute name\n");
> > +		ret = -ENOMEM;
> > +		goto out_free_timer;
> > +	}
> > +	info->timer->attr.attr.mode = S_IRUGO;
> > +	info->timer->attr.show = idletimer_tg_show;
> > +
> > +	ret = sysfs_create_file(idletimer_tg_kobj, &info->timer->attr.attr);
> > +	if (ret < 0) {
> > +		pr_debug("couldn't add file to sysfs");
> > +		goto out_free_attr;
> > +	}
> > +
> > +	list_add(&info->timer->entry, &idletimer_tg_list);
> > +
> > +	setup_timer(&info->timer->timer, idletimer_tg_expired,
> > +		    (unsigned long) info->timer);
> > +	info->timer->refcnt = 1;
> > +
> > +	mod_timer(&info->timer->timer,
> > +		  msecs_to_jiffies(info->timeout * 1000) + jiffies);
> > +
> > +	INIT_WORK(&info->timer->work, idletimer_tg_work);
> > +
> > +	return 0;
> > +
> > +out_free_attr:
> > +	kfree(info->timer->attr.attr.name);
> > +out_free_timer:
> > +	kfree(info->timer);
> > +out:
> > +	return ret;
> > +}
> > +
> > +/*
> > + * The actual xt_tables plugin.
> > + */
> > +static unsigned int idletimer_tg_target(struct sk_buff *skb,
> > +					 const struct xt_action_param *par)
> > +{
> > +	const struct idletimer_tg_info *info = par->targinfo;
> > +
> > +	pr_debug("resetting timer %s, timeout period %u\n",
> > +		 info->label, info->timeout);
> > +
> > +	mutex_lock(&list_mutex);
> >   
> 
> You can't take the mutex in the target function. What is it supposed to
> protect again?

Hmmmm... I was thinking that info->timer could be freed while this
function is executing.  But I guess the call to this function is already
protected against that, right?

I'll remove the mutex from here.


> > +
> > +	BUG_ON(!info->timer);
> > +
> > +	mod_timer(&info->timer->timer,
> > +		  msecs_to_jiffies(info->timeout * 1000) + jiffies);
> > +
> > +	mutex_unlock(&list_mutex);
> > +
> > +	return XT_CONTINUE;
> > +}
> > +
> 


-- 
Cheers,
Luca.


      reply	other threads:[~2010-06-14 14:59 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-06-11 14:01 [PATCH v4] netfilter: Xtables: idletimer target implementation Luciano Coelho
2010-06-14 14:39 ` Luciano Coelho
2010-06-14 14:48 ` Patrick McHardy
2010-06-14 14:59   ` Luciano Coelho [this message]

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=1276527564.2092.42.camel@chilepepper \
    --to=luciano.coelho@nokia.com \
    --cc=jengelh@medozas.de \
    --cc=kaber@trash.net \
    --cc=netdev@vger.kernel.org \
    --cc=netfilter@vger.kernel.org \
    --cc=timo.teras@iki.fi \
    /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).