All of lore.kernel.org
 help / color / mirror / Atom feed
From: Patrick McHardy <kaber@trash.net>
To: Adam Nielsen <a.nielsen@shikadi.net>
Cc: Netfilter Developer Mailing List
	<netfilter-devel@vger.kernel.org>,
	rpurdie@linux.intel.com
Subject: Re: [PATCH 2/2 v4] New netfilter target to trigger LED devices
Date: Thu, 12 Feb 2009 06:27:40 +0100	[thread overview]
Message-ID: <4993B34C.1020307@trash.net> (raw)
In-Reply-To: <49934702.9060909@shikadi.net>

Adam Nielsen wrote:
> +static unsigned int
> +led_tg(struct sk_buff *skb, const struct xt_target_param *par)
> +{
> +    const struct xt_led_info *ledinfo = par->targinfo;
> +    /*noconst*/struct xt_led_info_internal *ledinternal = 
> ledinfo->internal_data;
> +
> +    /*
> +     * Make sure the timer callback doesn't go switching the LED off while
> +     * we're figuring out what to do
> +     */
> +    if (ledinfo->delay > 0) {
> +        mutex_lock(&ledinternal->led_changing_state);

You can't use a mutex here, this might be running in softirq context.
Is locking necessary at all? Whats the worst that might happen? The
LED might forget to blink once? :)

> +static bool led_tg_check(const struct xt_tgchk_param *par)
> +{
> +    /*noconst*/ struct xt_led_info *ledinfo = par->targinfo;
> +    struct xt_led_info_internal *ledinternal;
> +    int err;
> +
> +    if (ledinfo->id[0] == '\0') {
> +        printk(KERN_CRIT KBUILD_MODNAME ": No 'id' parameter given.\n");
> +        return false;
> +    }

I guess KERN_ERR or default level is enough.

> +    if (!(ledinternal = kzalloc(sizeof(struct xt_led_info_internal), 
> GFP_KERNEL))) {
> +        printk(KERN_CRIT KBUILD_MODNAME ": out of memory\n");
> +        return false;
> +    }

Please seperate assignments from comparisons.

> +
> +    ledinternal->netfilter_led_trigger.name = ledinfo->id;
> +    mutex_init(&ledinternal->led_changing_state);
> +
> +    printk(KERN_NOTICE KBUILD_MODNAME ": Adding led trigger \"%s\"\n",
> +        ledinfo->id);

Too noisy, no printks except errors please.

> +
> +    err = led_trigger_register(&ledinternal->netfilter_led_trigger);
> +    if (err) {
> +        printk(KERN_CRIT KBUILD_MODNAME
> +            ": led_trigger_register() failed\n");
> +        if (err == -EEXIST) {
> +            printk(KERN_CRIT KBUILD_MODNAME
> +                ": Trigger name is already in use.\n");
> +        }
> +        goto exit_alloc;
> +    }
> +
> +    /* See if we need to set up a timer */
> +    if (ledinfo->delay > 0)
> +        setup_timer(&ledinternal->timer, led_timeout_callback,
> +            (unsigned long) ledinfo);
> +
> +    ledinfo->internal_data = ledinternal;
> +
> +    return true;
> +
> +exit_alloc:
> +    kfree(ledinternal);
> +
> +    return false;
> +}
> +
> +static void led_tg_destroy(const struct xt_tgdtor_param *par)
> +{
> +    const struct xt_led_info *ledinfo = par->targinfo;
> +    /*noconst*/struct xt_led_info_internal *ledinternal = 
> ledinfo->internal_data;
> +
> +    printk(KERN_NOTICE KBUILD_MODNAME ": Removing led trigger \"%s\"\n",
> +        ledinternal->netfilter_led_trigger.name);
> +
> +    if (ledinfo->delay > 0)
> +        del_timer_sync(&ledinternal->timer);
> +
> +    led_trigger_unregister(&ledinternal->netfilter_led_trigger);
> +    kfree(ledinternal);
> +}

> +
> +static int __init led_tg_init(void)
> +{
> +    printk(KERN_NOTICE KBUILD_MODNAME ": Registering LED netfilter 
> target\n");

This is too noisy, please remove this.

> +    return xt_register_target(&led_tg_reg);
> +}
> +
> +static void __exit led_tg_exit(void)
> +{
> +    printk(KERN_NOTICE KBUILD_MODNAME ": Unregistering LED netfilter 
> target\n");
> +    xt_unregister_target(&led_tg_reg);
> +}
> 

  reply	other threads:[~2009-02-12  5:27 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-02-11 21:45 [PATCH 2/2 v4] New netfilter target to trigger LED devices Adam Nielsen
2009-02-12  5:27 ` Patrick McHardy [this message]
2009-02-12 11:51   ` [PATCH 2/2 v5] " Adam Nielsen
2009-02-16 16:03     ` Patrick McHardy
2009-02-17 13:50       ` Richard Purdie
2009-02-18 14:14         ` Patrick McHardy
2009-02-18 22:20           ` Adam Nielsen
2009-02-19 10:14             ` Patrick McHardy
2009-02-20  9:57             ` Patrick McHardy
2009-02-22 14:16               ` Adam Nielsen
2009-02-24 13:51                 ` Patrick McHardy

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=4993B34C.1020307@trash.net \
    --to=kaber@trash.net \
    --cc=a.nielsen@shikadi.net \
    --cc=netfilter-devel@vger.kernel.org \
    --cc=rpurdie@linux.intel.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.