Skip to content

Commit

Permalink
pktgen: simplify error handling in pgctrl_write()
Browse files Browse the repository at this point in the history
The 'out' label is just a relict from previous times as pgctrl_write()
had multiple error paths. Get rid of it and simply return right away
on errors.

Cc: "David S. Miller" <davem@davemloft.net>
Signed-off-by: Mathias Krause <minipli@googlemail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Mathias Krause authored and David S. Miller committed Feb 24, 2014
1 parent 20b0c71 commit 0945574
Showing 1 changed file with 6 additions and 13 deletions.
19 changes: 6 additions & 13 deletions net/core/pktgen.c
Original file line number Diff line number Diff line change
Expand Up @@ -476,25 +476,21 @@ static int pgctrl_show(struct seq_file *seq, void *v)
static ssize_t pgctrl_write(struct file *file, const char __user *buf,
size_t count, loff_t *ppos)
{
int err = 0;
char data[128];
struct pktgen_net *pn = net_generic(current->nsproxy->net_ns, pg_net_id);

if (!capable(CAP_NET_ADMIN)) {
err = -EPERM;
goto out;
}
if (!capable(CAP_NET_ADMIN))
return -EPERM;

if (count == 0)
return -EINVAL;

if (count > sizeof(data))
count = sizeof(data);

if (copy_from_user(data, buf, count)) {
err = -EFAULT;
goto out;
}
if (copy_from_user(data, buf, count))
return -EFAULT;

data[count - 1] = 0; /* Strip trailing '\n' and terminate string */

if (!strcmp(data, "stop"))
Expand All @@ -509,10 +505,7 @@ static ssize_t pgctrl_write(struct file *file, const char __user *buf,
else
pr_warning("Unknown command: %s\n", data);

err = count;

out:
return err;
return count;
}

static int pgctrl_open(struct inode *inode, struct file *file)
Expand Down

0 comments on commit 0945574

Please sign in to comment.