All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/2] vfio: ccw: code cleanup and bugfix
@ 2017-04-12  9:08 Dong Jia Shi
  2017-04-12  9:08 ` [PATCH 1/2] vfio: ccw: remove unnecessary NULL checks of a pointer Dong Jia Shi
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Dong Jia Shi @ 2017-04-12  9:08 UTC (permalink / raw)
  To: kvm, linux-s390; +Cc: bjsdjshi, cornelia.huck, borntraeger, dan.carpenter

This series have two bugfix patches.

Patch #1 fixes a bug that was pointed out by Dan Carpenter:
[bug report] vfio: ccw: introduce a finite state machine
Message-ID: <20170404120223.GA8525@mwanda>

Patch #2 fixes another bug that was noticed by Cornelia Huck during the
discussion on the above thread.

The code base is:
https://git.kernel.org/pub/scm/linux/kernel/git/kvms390/vfio-ccw.git vfio-ccw-v0

Dong Jia Shi (2):
  vfio: ccw: remove unnecessary NULL checks of a pointer
  vfio: ccw: improve error handling for vfio_ccw_mdev_remove

 drivers/s390/cio/vfio_ccw_fsm.c |  6 +-----
 drivers/s390/cio/vfio_ccw_ops.c | 34 ++++++----------------------------
 2 files changed, 7 insertions(+), 33 deletions(-)

-- 
2.10.2

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 1/2] vfio: ccw: remove unnecessary NULL checks of a pointer
  2017-04-12  9:08 [PATCH 0/2] vfio: ccw: code cleanup and bugfix Dong Jia Shi
@ 2017-04-12  9:08 ` Dong Jia Shi
  2017-04-12  9:08 ` [PATCH 2/2] vfio: ccw: improve error handling for vfio_ccw_mdev_remove Dong Jia Shi
  2017-04-12 10:47 ` [PATCH 0/2] vfio: ccw: code cleanup and bugfix Cornelia Huck
  2 siblings, 0 replies; 4+ messages in thread
From: Dong Jia Shi @ 2017-04-12  9:08 UTC (permalink / raw)
  To: kvm, linux-s390; +Cc: bjsdjshi, cornelia.huck, borntraeger, dan.carpenter

Remove several unnecessary checks for the @private pointer, since it
can never be NULL in these places.

Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Dong Jia Shi <bjsdjshi@linux.vnet.ibm.com>
---
 drivers/s390/cio/vfio_ccw_fsm.c |  6 +-----
 drivers/s390/cio/vfio_ccw_ops.c | 17 -----------------
 2 files changed, 1 insertion(+), 22 deletions(-)

diff --git a/drivers/s390/cio/vfio_ccw_fsm.c b/drivers/s390/cio/vfio_ccw_fsm.c
index 55b6cc5..80a0559c 100644
--- a/drivers/s390/cio/vfio_ccw_fsm.c
+++ b/drivers/s390/cio/vfio_ccw_fsm.c
@@ -161,12 +161,8 @@ static void fsm_io_request(struct vfio_ccw_private *private,
 static void fsm_irq(struct vfio_ccw_private *private,
 		    enum vfio_ccw_event event)
 {
-	struct irb *irb;
+	struct irb *irb = this_cpu_ptr(&cio_irb);
 
-	if (!private)
-		return;
-
-	irb = this_cpu_ptr(&cio_irb);
 	memcpy(&private->irb, irb, sizeof(*irb));
 
 	queue_work(vfio_ccw_work_q, &private->io_work);
diff --git a/drivers/s390/cio/vfio_ccw_ops.c b/drivers/s390/cio/vfio_ccw_ops.c
index b2e6154..55d0c87 100644
--- a/drivers/s390/cio/vfio_ccw_ops.c
+++ b/drivers/s390/cio/vfio_ccw_ops.c
@@ -19,9 +19,6 @@ static int vfio_ccw_mdev_reset(struct mdev_device *mdev)
 	int ret;
 
 	private = dev_get_drvdata(mdev_parent_dev(mdev));
-	if (!private)
-		return -ENODEV;
-
 	sch = private->sch;
 	/*
 	 * TODO:
@@ -49,9 +46,6 @@ static int vfio_ccw_mdev_notifier(struct notifier_block *nb,
 	struct vfio_ccw_private *private =
 		container_of(nb, struct vfio_ccw_private, nb);
 
-	if (!private)
-		return NOTIFY_STOP;
-
 	/*
 	 * Vendor drivers MUST unpin pages in response to an
 	 * invalidation.
@@ -134,9 +128,6 @@ static int vfio_ccw_mdev_remove(struct mdev_device *mdev)
 		dev_get_drvdata(mdev_parent_dev(mdev));
 	int ret;
 
-	if (!private)
-		goto out;
-
 	if ((private->state == VFIO_CCW_STATE_NOT_OPER) ||
 	    (private->state == VFIO_CCW_STATE_STANDBY))
 		goto out;
@@ -187,9 +178,6 @@ static ssize_t vfio_ccw_mdev_read(struct mdev_device *mdev,
 		return -EINVAL;
 
 	private = dev_get_drvdata(mdev_parent_dev(mdev));
-	if (!private)
-		return -ENODEV;
-
 	region = &private->io_region;
 	if (copy_to_user(buf, (void *)region + *ppos, count))
 		return -EFAULT;
@@ -209,8 +197,6 @@ static ssize_t vfio_ccw_mdev_write(struct mdev_device *mdev,
 		return -EINVAL;
 
 	private = dev_get_drvdata(mdev_parent_dev(mdev));
-	if (!private)
-		return -ENODEV;
 	if (private->state != VFIO_CCW_STATE_IDLE)
 		return -EACCES;
 
@@ -274,9 +260,6 @@ static int vfio_ccw_mdev_set_irqs(struct mdev_device *mdev,
 		return -EINVAL;
 
 	private = dev_get_drvdata(mdev_parent_dev(mdev));
-	if (!private)
-		return -ENODEV;
-
 	ctx = &private->io_trigger;
 
 	switch (flags & VFIO_IRQ_SET_DATA_TYPE_MASK) {
-- 
2.10.2

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 2/2] vfio: ccw: improve error handling for vfio_ccw_mdev_remove
  2017-04-12  9:08 [PATCH 0/2] vfio: ccw: code cleanup and bugfix Dong Jia Shi
  2017-04-12  9:08 ` [PATCH 1/2] vfio: ccw: remove unnecessary NULL checks of a pointer Dong Jia Shi
@ 2017-04-12  9:08 ` Dong Jia Shi
  2017-04-12 10:47 ` [PATCH 0/2] vfio: ccw: code cleanup and bugfix Cornelia Huck
  2 siblings, 0 replies; 4+ messages in thread
From: Dong Jia Shi @ 2017-04-12  9:08 UTC (permalink / raw)
  To: kvm, linux-s390; +Cc: bjsdjshi, cornelia.huck, borntraeger, dan.carpenter

When vfio_ccw_mdev_reset fails during the remove process of the mdev,
the current implementation simply returns.

The failure indicates that the subchannel device is in a NOT_OPER state,
thus the right thing to do should be removing the mdev.

While we are at here, reverse the condition check to make the code more
concise and readable.

Signed-off-by: Dong Jia Shi <bjsdjshi@linux.vnet.ibm.com>
---
 drivers/s390/cio/vfio_ccw_ops.c | 17 ++++++-----------
 1 file changed, 6 insertions(+), 11 deletions(-)

diff --git a/drivers/s390/cio/vfio_ccw_ops.c b/drivers/s390/cio/vfio_ccw_ops.c
index 55d0c87..e72abbc 100644
--- a/drivers/s390/cio/vfio_ccw_ops.c
+++ b/drivers/s390/cio/vfio_ccw_ops.c
@@ -126,19 +126,14 @@ static int vfio_ccw_mdev_remove(struct mdev_device *mdev)
 {
 	struct vfio_ccw_private *private =
 		dev_get_drvdata(mdev_parent_dev(mdev));
-	int ret;
-
-	if ((private->state == VFIO_CCW_STATE_NOT_OPER) ||
-	    (private->state == VFIO_CCW_STATE_STANDBY))
-		goto out;
-
-	ret = vfio_ccw_mdev_reset(mdev);
-	if (ret)
-		return ret;
 
-	private->state = VFIO_CCW_STATE_STANDBY;
+	if ((private->state != VFIO_CCW_STATE_NOT_OPER) &&
+	    (private->state != VFIO_CCW_STATE_STANDBY)) {
+		if (!vfio_ccw_mdev_reset(mdev))
+			private->state = VFIO_CCW_STATE_STANDBY;
+		/* The state will be NOT_OPER on error. */
+	}
 
-out:
 	private->mdev = NULL;
 	atomic_inc(&private->avail);
 
-- 
2.10.2

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH 0/2] vfio: ccw: code cleanup and bugfix
  2017-04-12  9:08 [PATCH 0/2] vfio: ccw: code cleanup and bugfix Dong Jia Shi
  2017-04-12  9:08 ` [PATCH 1/2] vfio: ccw: remove unnecessary NULL checks of a pointer Dong Jia Shi
  2017-04-12  9:08 ` [PATCH 2/2] vfio: ccw: improve error handling for vfio_ccw_mdev_remove Dong Jia Shi
@ 2017-04-12 10:47 ` Cornelia Huck
  2 siblings, 0 replies; 4+ messages in thread
From: Cornelia Huck @ 2017-04-12 10:47 UTC (permalink / raw)
  To: Dong Jia Shi; +Cc: kvm, linux-s390, borntraeger, dan.carpenter

On Wed, 12 Apr 2017 11:08:14 +0200
Dong Jia Shi <bjsdjshi@linux.vnet.ibm.com> wrote:

> This series have two bugfix patches.
> 
> Patch #1 fixes a bug that was pointed out by Dan Carpenter:
> [bug report] vfio: ccw: introduce a finite state machine
> Message-ID: <20170404120223.GA8525@mwanda>
> 
> Patch #2 fixes another bug that was noticed by Cornelia Huck during the
> discussion on the above thread.
> 
> The code base is:
> https://git.kernel.org/pub/scm/linux/kernel/git/kvms390/vfio-ccw.git vfio-ccw-v0
> 
> Dong Jia Shi (2):
>   vfio: ccw: remove unnecessary NULL checks of a pointer
>   vfio: ccw: improve error handling for vfio_ccw_mdev_remove
> 
>  drivers/s390/cio/vfio_ccw_fsm.c |  6 +-----
>  drivers/s390/cio/vfio_ccw_ops.c | 34 ++++++----------------------------
>  2 files changed, 7 insertions(+), 33 deletions(-)
> 

Thanks, applied.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2017-04-12 10:47 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-04-12  9:08 [PATCH 0/2] vfio: ccw: code cleanup and bugfix Dong Jia Shi
2017-04-12  9:08 ` [PATCH 1/2] vfio: ccw: remove unnecessary NULL checks of a pointer Dong Jia Shi
2017-04-12  9:08 ` [PATCH 2/2] vfio: ccw: improve error handling for vfio_ccw_mdev_remove Dong Jia Shi
2017-04-12 10:47 ` [PATCH 0/2] vfio: ccw: code cleanup and bugfix Cornelia Huck

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.