lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20151009145244.GB20559@Red>
Date:	Fri, 9 Oct 2015 16:52:44 +0200
From:	LABBE Corentin <montjoie.mailing@...il.com>
To:	cpaul@...hat.com
Cc:	David Herrmann <dh.herrmann@...il.com>,
	Dmitry Torokhov <dmitry.torokhov@...il.com>,
	linux-kernel <linux-kernel@...r.kernel.org>,
	Linux API <linux-api@...r.kernel.org>,
	Andrew Morton <akpm@...ux-foundation.org>,
	Mauro Carvalho Chehab <mchehab@....samsung.com>,
	Greg KH <gregkh@...uxfoundation.org>,
	Arnd Bergmann <arnd@...db.de>, Joe Perches <joe@...ches.com>,
	Jiri Slaby <jslaby@...e.com>,
	Vishnu Patekar <vishnupatekar0510@...il.com>,
	Sebastian Ott <sebott@...ux.vnet.ibm.com>,
	Benjamin Tissoires <benjamin.tissoires@...hat.com>,
	Hans de Goede <hdegoede@...hat.com>,
	linux-doc@...r.kernel.org
Subject: Re: [PATCH v8] Input: Add userio module

On Fri, Oct 09, 2015 at 10:30:53AM -0400, cpaul@...hat.com wrote:
> From: Stephen Chandler Paul <cpaul@...hat.com>
> +
> +static ssize_t userio_char_read(struct file *file, char __user *user_buffer,
> +				size_t count, loff_t *ppos)
> +{
> +	struct userio_device *userio = file->private_data;
> +	int ret;
> +	size_t nonwrap_len, copylen;
> +	unsigned char buf[USERIO_BUFSIZE];
> +	unsigned long flags;
> +
> +	if (!count)
> +		return 0;
> +
> +	/*
> +	 * By the time we get here, the data that was waiting might have been
> +	 * taken by another thread. Grab the mutex and check if there's still
> +	 * any data waiting, otherwise repeat this process until we have data
> +	 * (unless the file descriptor is non-blocking of course)
> +	 */
> +	for (;;) {
> +		spin_lock_irqsave(&userio->buf_lock, flags);
> +
> +		if (userio->head != userio->tail)
> +			break;
> +
> +		spin_unlock_irqrestore(&userio->buf_lock, flags);
> +
> +		if (file->f_flags & O_NONBLOCK)
> +			return -EAGAIN;
> +
> +		ret = wait_event_interruptible(userio->waitq,
> +					       userio->head != userio->tail);
> +		if (ret)
> +			return ret;
> +	}
> +
> +	nonwrap_len = CIRC_CNT_TO_END(userio->head, userio->tail,
> +				      USERIO_BUFSIZE);
> +	copylen = min(nonwrap_len, count);
> +	memcpy(buf, &userio->buf[userio->tail], copylen);
> +
> +	userio->tail = (userio->tail + copylen) % USERIO_BUFSIZE;
> +
> +	spin_unlock_irqrestore(&userio->buf_lock, flags);
> +
> +	if (copy_to_user(user_buffer, buf, copylen))
> +		return -EFAULT;
> +
> +	return copylen;
> +}

Hello

I think you could simplify by just return copy_to_user() since it return copylen in case of success.

Regards

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ