Thread (25 messages) 25 messages, 3 authors, 2019-06-08

RE: [PATCH V4 04/12] misc: xilinx_sdfec: Add open, close and ioctl

From: Dragan Cvetic <hidden>
Date: 2019-06-06 18:22:15
Also in: linux-devicetree, lkml

-----Original Message-----
From: Greg KH [mailto:gregkh@linuxfoundation.org]
Sent: Thursday 6 June 2019 14:29
To: Dragan Cvetic <redacted>
Cc: arnd@arndb.de; Michal Simek <redacted>; 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 [off-list ref]
Subject: Re: [PATCH V4 04/12] misc: xilinx_sdfec: Add open, close and ioctl

On Sat, May 25, 2019 at 12:37:17PM +0100, Dragan Cvetic wrote:
quoted
+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.
Accepted.
Will remove them.
quoted
+
+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.
Accepted.
Will remove if statement.
quoted
+
+	if (_IOC_TYPE(cmd) != XSDFEC_MAGIC)
+		return -ENOTTY;
How can this happen?
Accepted.
Will be removed.
quoted
+
+	/* 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.
Accepted.
Will remove log.
thanks,

greg k-h
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help