netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Ben Hutchings <bhutchings@solarflare.com>
To: Sarveshwar Bandi <sarveshwarb@serverengines.com>
Cc: davem@davemloft.net, netdev@vger.kernel.org
Subject: Re: [PATCH] Code changes to handle dev private ioctl
Date: Fri, 22 May 2009 15:21:19 +0100	[thread overview]
Message-ID: <1243002079.3192.11.camel@achroite> (raw)
In-Reply-To: <20090522133315.GA13610@serverengines.com>

On Fri, 2009-05-22 at 19:03 +0530, Sarveshwar Bandi wrote:
[...]
> diff --git a/drivers/net/benet/be_main.c b/drivers/net/benet/be_main.c
> index ae2f6b5..8329e07 100644
> --- a/drivers/net/benet/be_main.c
> +++ b/drivers/net/benet/be_main.c
> @@ -562,6 +562,53 @@ static void be_vlan_rem_vid(struct net_d
>  	be_vid_config(netdev);
>  }
>  
> +static int be_do_ioctl(struct net_device *netdev,
> +			struct ifreq *ifr, int cmd)
> +{
> +	struct be_adapter *adapter = netdev_priv(netdev);
> +	struct be_cmd_req_hdr req;
> +	struct be_cmd_resp_hdr *resp;
> +	void *data = ifr->ifr_data;
> +	void *va;
> +	dma_addr_t dma;
> +	u32 req_size, resp_size;
> +	int status;
> +
> +	switch (cmd) {
> +	case SIOCDEVPRIVATE:

This probably needs a capability check, depending on what it's actually
doing.  Most configuration ioctl implementation use:

		if (!capable(CAP_NET_ADMIN))
			return -EPERM;

> +		if (copy_from_user(&req, (struct be_cmd_req_hdr *)data,
> +			sizeof(struct be_cmd_req_hdr)))
> +			return -EFAULT;
> +
> +		req_size = req.request_length + sizeof(struct be_cmd_req_hdr);
> +
> +		va = pci_alloc_consistent(adapter->pdev, req_size, &dma);

Needs an error check.

> +		if (copy_from_user(va, (void *)data, req_size)) {
> +			pci_free_consistent(adapter->pdev, req_size, va, dma);
> +			return -EFAULT;
> +		}
> +
> +		status = be_cmd_pass_ext_ioctl(&adapter->ctrl, dma, req_size);
> +		if (!status) {
> +			resp = (struct be_cmd_resp_hdr *) va;
> +			resp_size = resp->response_length + sizeof(*resp);
> +			if (copy_to_user((void *)data, va, resp_size)) {
> +				pci_free_consistent(adapter->pdev,
> +							req_size, va, dma);
> +				return -EFAULT;
> +			}
> +		} else {
> +			pci_free_consistent(adapter->pdev, req_size, va, dma);
> +			return -EFAULT;

Why repeat this cleanup and return so many times?  Kernel style is to
put cleanup code at the end of the function and use "goto" to get there
in case of error.

> +		}
> +		pci_free_consistent(adapter->pdev, req_size, va, dma);
> +		break;
> +	default:
> +		return -EFAULT;
[...]

Should be -EOPNOTSUPP.

Ben.

-- 
Ben Hutchings, Senior Software Engineer, Solarflare Communications
Not speaking for my employer; that's the marketing department's job.
They asked us to note that Solarflare product names are trademarked.


      reply	other threads:[~2009-05-22 14:21 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-05-22 13:33 [PATCH] Code changes to handle dev private ioctl Sarveshwar Bandi
2009-05-22 14:21 ` Ben Hutchings [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=1243002079.3192.11.camel@achroite \
    --to=bhutchings@solarflare.com \
    --cc=davem@davemloft.net \
    --cc=netdev@vger.kernel.org \
    --cc=sarveshwarb@serverengines.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 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).