public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Dan Carpenter <dan.carpenter@oracle.com>
To: Dominik Paulus <dominik.paulus@fau.de>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Anthony Foiani <anthony.foiani@gmail.com>,
	devel@driverdev.osuosl.org, linux-kernel@i4.cs.fau.de,
	Kurt Kanzenbach <ly80toro@cip.cs.fau.de>,
	linux-kernel@vger.kernel.org, tobias.polzer@fau.de,
	Ilija Hadzic <ihadzic@research.bell-labs.com>
Subject: Re: [PATCHv3  02/16] staging: usbip: Add kernel support for client ACLs
Date: Mon, 30 Sep 2013 11:29:42 +0300	[thread overview]
Message-ID: <20130930082942.GH6192@mwanda> (raw)
In-Reply-To: <1380390173-3746-2-git-send-email-dominik.paulus@fau.de>

The main thing is that there is an IS_ERR vs NULL check.  The rest is
just style nits.

On Sat, Sep 28, 2013 at 07:42:39PM +0200, Dominik Paulus wrote:
> +static ssize_t store_acl(struct device *dev, struct device_attribute *attr,
> +			const char *buf, size_t count)
> +{
> +	struct stub_device *sdev = dev_get_drvdata(dev);
> +	int retval = 0;
> +
> +	if (!sdev)
> +		return -ENODEV;

Can this even happen?  If not, don't check for impossible conditions it
is sloppy.

> +
> +	if (count >= PAGE_SIZE)
> +		/* Prevent storing oversized ACLs in kernel memory */
> +		return -EINVAL;
> +

Put parenthesis around multi-line indents.  But in this case just delete
the obvious comment.

> +	/* Store ACL */

Delete obvious comment.

> +	spin_lock_irq(&sdev->ip_lock);
> +	kfree(sdev->acls);
> +	sdev->acls = kstrdup(buf, GFP_KERNEL);

kstrdup() returns a NULL on error not an error pointer.  Configure vim
to use cscope and run make cscope.

> +	if (IS_ERR(sdev->acls)) {
> +		retval = PTR_ERR(sdev->acls);
> +		sdev->acls = NULL;
> +	} else {
> +		retval = strlen(sdev->acls);
> +	}
> +	spin_unlock_irq(&sdev->ip_lock);
> +
> +	return retval;
> +}
> +
> +/*
> + * This functions prints all allowed IP addrs for this dev
> + */
> +static ssize_t show_acl(struct device *dev, struct device_attribute *attr,
> +		       char *buf)
> +{
> +	struct stub_device *sdev = dev_get_drvdata(dev);
> +	int retval = 0;

Don't initialize things if you don't use the value.  (It stops GCC from
warning about uninitialized variables properly).

> +
> +	if (!sdev)
> +		return -ENODEV;
> +
> +	spin_lock_irq(&sdev->ip_lock);
> +	if (sdev->acls == NULL) {
> +		retval = 0;
> +	} else {
> +		strcpy(buf, sdev->acls);
> +		retval = strlen(buf);
> +	}
> +	spin_unlock_irq(&sdev->ip_lock);
> +
> +	return retval;
> +}
> +static DEVICE_ATTR(usbip_acl, S_IWUSR | S_IRUGO, show_acl, store_acl);
> +
>  static int stub_add_files(struct device *dev)
>  {
>  	int err = 0;
> @@ -157,9 +213,13 @@ static int stub_add_files(struct device *dev)
>  	err = device_create_file(dev, &dev_attr_usbip_debug);
>  	if (err)
>  		goto err_debug;
> +	err = device_create_file(dev, &dev_attr_usbip_acl);
> +	if (err)
> +		goto err_ip;
>  
>  	return 0;
> -
> +err_ip:
> +	device_remove_file(dev, &dev_attr_usbip_debug);
>  err_debug:
>  	device_remove_file(dev, &dev_attr_usbip_sockfd);
>  err_sockfd:

I wasn't able to figure out what the "ip" part of "err_ip" meant...

Really these are all poor label names.  They are based on the goto
location instead of the label location.

> @@ -173,6 +233,7 @@ static void stub_remove_files(struct device *dev)
>  	device_remove_file(dev, &dev_attr_usbip_status);
>  	device_remove_file(dev, &dev_attr_usbip_sockfd);
>  	device_remove_file(dev, &dev_attr_usbip_debug);
> +	device_remove_file(dev, &dev_attr_usbip_acl);
>  }
>  
>  static void stub_shutdown_connection(struct usbip_device *ud)
> @@ -306,12 +367,14 @@ static struct stub_device *stub_device_alloc(struct usb_device *udev,
>  	sdev->ud.status		= SDEV_ST_AVAILABLE;
>  	spin_lock_init(&sdev->ud.lock);
>  	sdev->ud.tcp_socket	= NULL;
> +	sdev->acls = NULL;

This isn't really needed because we allocated sdev with kzalloc().


>  
>  	INIT_LIST_HEAD(&sdev->priv_init);
>  	INIT_LIST_HEAD(&sdev->priv_tx);
>  	INIT_LIST_HEAD(&sdev->priv_free);
>  	INIT_LIST_HEAD(&sdev->unlink_free);
>  	INIT_LIST_HEAD(&sdev->unlink_tx);
> +	spin_lock_init(&sdev->ip_lock);
>  	spin_lock_init(&sdev->priv_lock);
>  
>  	init_waitqueue_head(&sdev->tx_waitq);
> @@ -511,6 +574,9 @@ static void stub_disconnect(struct usb_interface *interface)
>  	usb_put_dev(sdev->udev);
>  	usb_put_intf(interface);
>  
> +	/* free ACL list */
> +	kfree(sdev->acls);
> +
>  	/* free sdev */
>  	busid_priv->sdev = NULL;
>  	stub_device_free(sdev);
> -- 
> 1.8.4
> 
> _______________________________________________
> devel mailing list
> devel@linuxdriverproject.org
> http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

  reply	other threads:[~2013-09-30  8:30 UTC|newest]

Thread overview: 53+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-09-13  9:55 [PATCHv2 0/11] staging: usbip: Userland crypto and ACLs Dominik Paulus
2013-09-13  9:55 ` [PATCHv2 01/11] staging: usbip: Fix IPv6 support in usbipd Dominik Paulus
2013-09-13  9:55 ` [PATCHv2 02/11] staging: usbip: Add support for client authentication Dominik Paulus
2013-09-13  9:55 ` [PATCHv2 03/11] staging: usbip: Add kernel support for client ACLs Dominik Paulus
2013-09-13  9:55 ` [PATCHv2 04/11] staging: usbip: Add CIDR matching helper functions Dominik Paulus
2013-09-13  9:55 ` [PATCHv2 05/11] staging: usbip: Add ACL support to usbip bind Dominik Paulus
2013-09-13  9:55 ` [PATCHv2 06/11] staging: usbip: Add support for ACLs in usbipd Dominik Paulus
2013-09-13  9:55 ` [PATCHv2 07/11] staging: usbip: Add proper error reporting Dominik Paulus
2013-09-13  9:55 ` [PATCHv2 08/11] staging: usbip: Handle usbip being started as user Dominik Paulus
2013-09-13  9:55 ` [PATCHv2 09/11] staging: usbip: Improve debug output Dominik Paulus
2013-09-13  9:56 ` [PATCHv2 10/11] staging: usbip: Separate protocol/program version Dominik Paulus
2013-09-13  9:56 ` [PATCHv2 11/11] staging: usbip: Increment version to 1.2.0 Dominik Paulus
2013-09-25 23:36 ` [PATCHv2 0/11] staging: usbip: Userland crypto and ACLs Greg Kroah-Hartman
2013-09-28 17:41   ` Dominik Paulus
2013-09-28 17:42   ` [PATCHv3 01/16] staging: usbip: Add support for client authentication Dominik Paulus
2013-09-28 17:42     ` [PATCHv3 02/16] staging: usbip: Add kernel support for client ACLs Dominik Paulus
2013-09-30  8:29       ` Dan Carpenter [this message]
2013-09-28 17:42     ` [PATCHv3 03/16] staging: usbip: Add CIDR matching helper functions Dominik Paulus
2013-09-28 17:42     ` [PATCHv3 04/16] staging: usbip: Add ACL support to usbip bind Dominik Paulus
2013-09-28 17:42     ` [PATCHv3 05/16] staging: usbip: Add support for ACLs in usbipd Dominik Paulus
2013-09-28 17:42     ` [PATCHv3 06/16] staging: usbip: Add proper error reporting Dominik Paulus
2013-09-28 17:42     ` [PATCHv3 07/16] staging: usbip: Handle usbip being started as user Dominik Paulus
2013-09-28 17:42     ` [PATCHv3 08/16] staging: usbip: Improve debug output Dominik Paulus
2013-09-28 17:42     ` [PATCHv3 09/16] staging: usbip: Separate protocol/program version Dominik Paulus
2013-09-28 17:42     ` [PATCHv3 10/16] staging: usbip: TLS for all userspace communication Dominik Paulus
2013-09-28 17:42     ` [PATCHv3 11/16] staging: usbip: Exchange session keys in userspace Dominik Paulus
2013-09-28 17:42     ` [PATCHv3 12/16] staging: usbip: Pass session keys to the kernel Dominik Paulus
2013-09-28 17:42     ` [PATCHv3 13/16] staging: usbip: Wrap kernel_sendmsg()/recvmsg() Dominik Paulus
2013-09-30 12:42       ` Dan Carpenter
2013-09-28 17:42     ` [PATCHv3 14/16] staging: usbip: Add encryption support to kernel Dominik Paulus
2013-09-30 12:38       ` Dan Carpenter
2013-10-19 14:39         ` [PATCHv4 00/16] staging: usbip: Add kernel support for client ACLs Dominik Paulus
2013-10-19 14:39           ` [PATCHv4 01/16] staging: usbip: Add support for client authentication Dominik Paulus
2013-10-19 14:39           ` [PATCHv4 02/16] staging: usbip: Add kernel support for client ACLs Dominik Paulus
2013-10-19 14:39           ` [PATCHv4 03/16] staging: usbip: Add CIDR matching helper functions Dominik Paulus
2013-10-19 14:39           ` [PATCHv4 04/16] staging: usbip: Add ACL support to usbip bind Dominik Paulus
2013-10-19 14:39           ` [PATCHv4 05/16] staging: usbip: Add support for ACLs in usbipd Dominik Paulus
2013-10-19 14:39           ` [PATCHv4 06/16] staging: usbip: Add proper error reporting Dominik Paulus
2013-10-25 13:26             ` Dan Carpenter
2013-10-19 14:39           ` [PATCHv4 07/16] staging: usbip: Handle usbip being started as user Dominik Paulus
2013-10-19 14:39           ` [PATCHv4 08/16] staging: usbip: Improve debug output Dominik Paulus
2013-10-19 14:39           ` [PATCHv4 09/16] staging: usbip: Separate protocol/program version Dominik Paulus
2013-10-19 14:39           ` [PATCHv4 10/16] staging: usbip: TLS for all userspace communication Dominik Paulus
2013-10-25 14:45             ` Dan Carpenter
2013-10-19 14:39           ` [PATCHv4 11/16] staging: usbip: Exchange session keys in userspace Dominik Paulus
2013-10-19 14:39           ` [PATCHv4 12/16] staging: usbip: Pass session keys to the kernel Dominik Paulus
2013-10-25 15:02             ` Dan Carpenter
2013-10-19 14:39           ` [PATCHv4 13/16] staging: usbip: Wrap kernel_sendmsg()/recvmsg() Dominik Paulus
2013-10-19 14:39           ` [PATCHv4 14/16] staging: usbip: Add encryption support to kernel Dominik Paulus
2013-10-19 14:39           ` [PATCHv4 15/16] staging: usbip: Update documentation Dominik Paulus
2013-10-19 14:39           ` [PATCHv4 16/16] staging: usbip: Increment version number to 1.2.1 Dominik Paulus
2013-09-28 17:42     ` [PATCHv3 15/16] staging: usbip: Update documentation Dominik Paulus
2013-09-28 17:42     ` [PATCHv3 16/16] staging: usbip: Increment version number to 1.2.1 Dominik Paulus

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=20130930082942.GH6192@mwanda \
    --to=dan.carpenter@oracle.com \
    --cc=anthony.foiani@gmail.com \
    --cc=devel@driverdev.osuosl.org \
    --cc=dominik.paulus@fau.de \
    --cc=gregkh@linuxfoundation.org \
    --cc=ihadzic@research.bell-labs.com \
    --cc=linux-kernel@i4.cs.fau.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=ly80toro@cip.cs.fau.de \
    --cc=tobias.polzer@fau.de \
    /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