All of lore.kernel.org
 help / color / mirror / Atom feed
From: Greg KH <gregkh@linuxfoundation.org>
To: Dragan Cvetic <dragan.cvetic@xilinx.com>
Cc: mark.rutland@arm.com, devicetree@vger.kernel.org, arnd@arndb.de,
	michal.simek@xilinx.com, linux-kernel@vger.kernel.org,
	robh+dt@kernel.org, Derek Kiernan <derek.kiernan@xilinx.com>,
	linux-arm-kernel@lists.infradead.org
Subject: Re: [PATCH V4 04/12] misc: xilinx_sdfec: Add open, close and ioctl
Date: Thu, 6 Jun 2019 15:28:42 +0200	[thread overview]
Message-ID: <20190606132842.GC7943@kroah.com> (raw)
In-Reply-To: <1558784245-108751-5-git-send-email-dragan.cvetic@xilinx.com>

On Sat, May 25, 2019 at 12:37:17PM +0100, Dragan Cvetic wrote:
> +static int xsdfec_dev_open(struct inode *iptr, struct file *fptr)
> +{
> +	return 0;
> +}
> +
> +static int xsdfec_dev_release(struct inode *iptr, struct file *fptr)
> +{
> +	return 0;
> +}

empty open/close functions are never needed, just drop them.

> +
> +static long xsdfec_dev_ioctl(struct file *fptr, unsigned int cmd,
> +			     unsigned long data)
> +{
> +	struct xsdfec_dev *xsdfec;
> +	void __user *arg = NULL;
> +	int rval = -EINVAL;
> +
> +	xsdfec = container_of(fptr->private_data, struct xsdfec_dev, miscdev);
> +	if (!xsdfec)
> +		return rval;

It is impossible for container_of() to return NULL, unless something
very magical and rare just happened.  It's just doing pointer math, you
can never check the return value of it.

> +
> +	if (_IOC_TYPE(cmd) != XSDFEC_MAGIC)
> +		return -ENOTTY;

How can this happen?

> +
> +	/* check if ioctl argument is present and valid */
> +	if (_IOC_DIR(cmd) != _IOC_NONE) {
> +		arg = (void __user *)data;
> +		if (!arg)
> +			return rval;
> +	}
> +
> +	switch (cmd) {
> +	default:
> +		/* Should not get here */
> +		dev_warn(xsdfec->dev, "Undefined SDFEC IOCTL");

Nice that userspace has a way to fill up the kernel log :(

Just return the correct error here, don't log it.

thanks,

greg k-h

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

WARNING: multiple messages have this Message-ID (diff)
From: Greg KH <gregkh@linuxfoundation.org>
To: Dragan Cvetic <dragan.cvetic@xilinx.com>
Cc: arnd@arndb.de, michal.simek@xilinx.com,
	linux-arm-kernel@lists.infradead.org, robh+dt@kernel.org,
	mark.rutland@arm.com, devicetree@vger.kernel.org,
	linux-kernel@vger.kernel.org,
	Derek Kiernan <derek.kiernan@xilinx.com>
Subject: Re: [PATCH V4 04/12] misc: xilinx_sdfec: Add open, close and ioctl
Date: Thu, 6 Jun 2019 15:28:42 +0200	[thread overview]
Message-ID: <20190606132842.GC7943@kroah.com> (raw)
In-Reply-To: <1558784245-108751-5-git-send-email-dragan.cvetic@xilinx.com>

On Sat, May 25, 2019 at 12:37:17PM +0100, Dragan Cvetic wrote:
> +static int xsdfec_dev_open(struct inode *iptr, struct file *fptr)
> +{
> +	return 0;
> +}
> +
> +static int xsdfec_dev_release(struct inode *iptr, struct file *fptr)
> +{
> +	return 0;
> +}

empty open/close functions are never needed, just drop them.

> +
> +static long xsdfec_dev_ioctl(struct file *fptr, unsigned int cmd,
> +			     unsigned long data)
> +{
> +	struct xsdfec_dev *xsdfec;
> +	void __user *arg = NULL;
> +	int rval = -EINVAL;
> +
> +	xsdfec = container_of(fptr->private_data, struct xsdfec_dev, miscdev);
> +	if (!xsdfec)
> +		return rval;

It is impossible for container_of() to return NULL, unless something
very magical and rare just happened.  It's just doing pointer math, you
can never check the return value of it.

> +
> +	if (_IOC_TYPE(cmd) != XSDFEC_MAGIC)
> +		return -ENOTTY;

How can this happen?

> +
> +	/* check if ioctl argument is present and valid */
> +	if (_IOC_DIR(cmd) != _IOC_NONE) {
> +		arg = (void __user *)data;
> +		if (!arg)
> +			return rval;
> +	}
> +
> +	switch (cmd) {
> +	default:
> +		/* Should not get here */
> +		dev_warn(xsdfec->dev, "Undefined SDFEC IOCTL");

Nice that userspace has a way to fill up the kernel log :(

Just return the correct error here, don't log it.

thanks,

greg k-h

  parent reply	other threads:[~2019-06-06 13:28 UTC|newest]

Thread overview: 64+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-05-25 11:37 [PATCH V4 00/12] misc: xilinx sd-fec drive Dragan Cvetic
2019-05-25 11:37 ` Dragan Cvetic
2019-05-25 11:37 ` Dragan Cvetic
2019-05-25 11:37 ` [PATCH V4 01/12] dt-bindings: xilinx-sdfec: Add SDFEC binding Dragan Cvetic
2019-05-25 11:37   ` Dragan Cvetic
2019-05-25 11:37   ` Dragan Cvetic
2019-05-25 11:37 ` [PATCH V4 02/12] misc: xilinx-sdfec: add core driver Dragan Cvetic
2019-05-25 11:37   ` Dragan Cvetic
2019-05-25 11:37   ` Dragan Cvetic
2019-06-06 13:25   ` Greg KH
2019-06-06 13:25     ` Greg KH
2019-06-06 18:16     ` Dragan Cvetic
2019-06-06 18:16       ` Dragan Cvetic
2019-06-06 19:04       ` Greg KH
2019-06-06 19:04         ` Greg KH
2019-05-25 11:37 ` [PATCH V4 03/12] misc: xilinx_sdfec: Add CCF support Dragan Cvetic
2019-05-25 11:37   ` Dragan Cvetic
2019-05-25 11:37   ` Dragan Cvetic
2019-05-25 11:37 ` [PATCH V4 04/12] misc: xilinx_sdfec: Add open, close and ioctl Dragan Cvetic
2019-05-25 11:37   ` Dragan Cvetic
2019-05-25 11:37   ` Dragan Cvetic
2019-06-06 13:26   ` Greg KH
2019-06-06 13:26     ` Greg KH
2019-06-06 18:18     ` Dragan Cvetic
2019-06-06 18:18       ` Dragan Cvetic
2019-06-06 13:28   ` Greg KH [this message]
2019-06-06 13:28     ` Greg KH
2019-06-06 18:22     ` Dragan Cvetic
2019-06-06 18:22       ` Dragan Cvetic
2019-06-07 10:58     ` Dragan Cvetic
2019-06-07 10:58       ` Dragan Cvetic
2019-06-07 15:57       ` Greg KH
2019-06-07 15:57         ` Greg KH
2019-06-08 19:40         ` Dragan Cvetic
2019-06-08 19:40           ` Dragan Cvetic
2019-06-08 19:40           ` Dragan Cvetic
2019-05-25 11:37 ` [PATCH V4 05/12] misc: xilinx_sdfec: Store driver config and state Dragan Cvetic
2019-05-25 11:37   ` Dragan Cvetic
2019-05-25 11:37   ` Dragan Cvetic
2019-05-25 11:37 ` [PATCH V4 06/12] misc: xilinx_sdfec: Add ability to configure turbo Dragan Cvetic
2019-05-25 11:37   ` Dragan Cvetic
2019-05-25 11:37   ` Dragan Cvetic
2019-05-25 11:37 ` [PATCH V4 07/12] misc: xilinx_sdfec: Add ability to configure LDPC Dragan Cvetic
2019-05-25 11:37   ` Dragan Cvetic
2019-05-25 11:37   ` Dragan Cvetic
2019-05-25 11:37 ` [PATCH V4 08/12] misc: xilinx_sdfec: Add ability to get/set config Dragan Cvetic
2019-05-25 11:37   ` Dragan Cvetic
2019-05-25 11:37   ` Dragan Cvetic
2019-05-25 11:37 ` [PATCH V4 09/12] misc: xilinx_sdfec: Support poll file operation Dragan Cvetic
2019-05-25 11:37   ` Dragan Cvetic
2019-05-25 11:37   ` Dragan Cvetic
2019-05-25 11:37 ` [PATCH V4 10/12] misc: xilinx_sdfec: Add stats & status ioctls Dragan Cvetic
2019-05-25 11:37   ` Dragan Cvetic
2019-05-25 11:37   ` Dragan Cvetic
2019-06-06 14:11   ` Greg KH
2019-06-06 14:11     ` Greg KH
2019-06-06 18:27     ` Dragan Cvetic
2019-06-06 18:27       ` Dragan Cvetic
2019-05-25 11:37 ` [PATCH V4 11/12] Docs: misc: xilinx_sdfec: Add documentation Dragan Cvetic
2019-05-25 11:37   ` Dragan Cvetic
2019-05-25 11:37   ` Dragan Cvetic
2019-05-25 11:37 ` [PATCH V4 12/12] MAINTAINERS: add maintainer for SD-FEC Dragan Cvetic
2019-05-25 11:37   ` Dragan Cvetic
2019-05-25 11:37   ` Dragan Cvetic

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=20190606132842.GC7943@kroah.com \
    --to=gregkh@linuxfoundation.org \
    --cc=arnd@arndb.de \
    --cc=derek.kiernan@xilinx.com \
    --cc=devicetree@vger.kernel.org \
    --cc=dragan.cvetic@xilinx.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=michal.simek@xilinx.com \
    --cc=robh+dt@kernel.org \
    /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.