All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] misc: mic: fix incorrect use of error codes in SCIF DMA driver
@ 2015-12-12  2:09 Eric Biggers
  2015-12-12  2:50 ` Sudeep Dutt
  0 siblings, 1 reply; 2+ messages in thread
From: Eric Biggers @ 2015-12-12  2:09 UTC (permalink / raw)
  To: sudeep.dutt
  Cc: ashutosh.dixit, nikhil.rao, gregkh, linux-kernel, Eric Biggers

The error code passed to ERR_PTR() always should be negated.  Also, the
return value of scif_add_mmu_notifier() was never checked.

Signed-off-by: Eric Biggers <ebiggers3@gmail.com>
---
 drivers/misc/mic/scif/scif_dma.c | 14 +++++---------
 1 file changed, 5 insertions(+), 9 deletions(-)

diff --git a/drivers/misc/mic/scif/scif_dma.c b/drivers/misc/mic/scif/scif_dma.c
index 95a13c6..f6aeebd 100644
--- a/drivers/misc/mic/scif/scif_dma.c
+++ b/drivers/misc/mic/scif/scif_dma.c
@@ -276,13 +276,10 @@ static struct scif_mmu_notif *
 scif_find_mmu_notifier(struct mm_struct *mm, struct scif_endpt_rma_info *rma)
 {
 	struct scif_mmu_notif *mmn;
-	struct list_head *item;
 
-	list_for_each(item, &rma->mmn_list) {
-		mmn = list_entry(item, struct scif_mmu_notif, list);
+	list_for_each_entry(mmn, &rma->mmn_list, list)
 		if (mmn->mm == mm)
 			return mmn;
-	}
 	return NULL;
 }
 
@@ -293,13 +290,12 @@ scif_add_mmu_notifier(struct mm_struct *mm, struct scif_endpt *ep)
 		 = kzalloc(sizeof(*mmn), GFP_KERNEL);
 
 	if (!mmn)
-		return ERR_PTR(ENOMEM);
+		return ERR_PTR(-ENOMEM);
 
 	scif_init_mmu_notifier(mmn, current->mm, ep);
-	if (mmu_notifier_register(&mmn->ep_mmu_notifier,
-				  current->mm)) {
+	if (mmu_notifier_register(&mmn->ep_mmu_notifier, current->mm)) {
 		kfree(mmn);
-		return ERR_PTR(EBUSY);
+		return ERR_PTR(-EBUSY);
 	}
 	list_add(&mmn->list, &ep->rma_info.mmn_list);
 	return mmn;
@@ -1730,7 +1726,7 @@ static int scif_rma_copy(scif_epd_t epd, off_t loffset, unsigned long addr,
 		mutex_lock(&ep->rma_info.mmn_lock);
 		mmn = scif_find_mmu_notifier(current->mm, &ep->rma_info);
 		if (!mmn)
-			scif_add_mmu_notifier(current->mm, ep);
+			mmn = scif_add_mmu_notifier(current->mm, ep);
 		mutex_unlock(&ep->rma_info.mmn_lock);
 		if (IS_ERR(mmn)) {
 			scif_put_peer_dev(spdev);
-- 
2.6.3


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

* Re: [PATCH] misc: mic: fix incorrect use of error codes in SCIF DMA driver
  2015-12-12  2:09 [PATCH] misc: mic: fix incorrect use of error codes in SCIF DMA driver Eric Biggers
@ 2015-12-12  2:50 ` Sudeep Dutt
  0 siblings, 0 replies; 2+ messages in thread
From: Sudeep Dutt @ 2015-12-12  2:50 UTC (permalink / raw)
  To: Eric Biggers
  Cc: Sudeep Dutt, ashutosh.dixit, nikhil.rao, gregkh, linux-kernel

On Fri, 2015-12-11 at 20:09 -0600, Eric Biggers wrote:
> The error code passed to ERR_PTR() always should be negated.  Also, the
> return value of scif_add_mmu_notifier() was never checked.
> 

Thanks for the patch Eric.

Reviewed-by: Sudeep Dutt <sudeep.dutt@intel.com>

> Signed-off-by: Eric Biggers <ebiggers3@gmail.com>
> ---
>  drivers/misc/mic/scif/scif_dma.c | 14 +++++---------
>  1 file changed, 5 insertions(+), 9 deletions(-)
> 
> diff --git a/drivers/misc/mic/scif/scif_dma.c b/drivers/misc/mic/scif/scif_dma.c
> index 95a13c6..f6aeebd 100644
> --- a/drivers/misc/mic/scif/scif_dma.c
> +++ b/drivers/misc/mic/scif/scif_dma.c
> @@ -276,13 +276,10 @@ static struct scif_mmu_notif *
>  scif_find_mmu_notifier(struct mm_struct *mm, struct scif_endpt_rma_info *rma)
>  {
>  	struct scif_mmu_notif *mmn;
> -	struct list_head *item;
>  
> -	list_for_each(item, &rma->mmn_list) {
> -		mmn = list_entry(item, struct scif_mmu_notif, list);
> +	list_for_each_entry(mmn, &rma->mmn_list, list)
>  		if (mmn->mm == mm)
>  			return mmn;
> -	}
>  	return NULL;
>  }
>  
> @@ -293,13 +290,12 @@ scif_add_mmu_notifier(struct mm_struct *mm, struct scif_endpt *ep)
>  		 = kzalloc(sizeof(*mmn), GFP_KERNEL);
>  
>  	if (!mmn)
> -		return ERR_PTR(ENOMEM);
> +		return ERR_PTR(-ENOMEM);
>  
>  	scif_init_mmu_notifier(mmn, current->mm, ep);
> -	if (mmu_notifier_register(&mmn->ep_mmu_notifier,
> -				  current->mm)) {
> +	if (mmu_notifier_register(&mmn->ep_mmu_notifier, current->mm)) {
>  		kfree(mmn);
> -		return ERR_PTR(EBUSY);
> +		return ERR_PTR(-EBUSY);
>  	}
>  	list_add(&mmn->list, &ep->rma_info.mmn_list);
>  	return mmn;
> @@ -1730,7 +1726,7 @@ static int scif_rma_copy(scif_epd_t epd, off_t loffset, unsigned long addr,
>  		mutex_lock(&ep->rma_info.mmn_lock);
>  		mmn = scif_find_mmu_notifier(current->mm, &ep->rma_info);
>  		if (!mmn)
> -			scif_add_mmu_notifier(current->mm, ep);
> +			mmn = scif_add_mmu_notifier(current->mm, ep);
>  		mutex_unlock(&ep->rma_info.mmn_lock);
>  		if (IS_ERR(mmn)) {
>  			scif_put_peer_dev(spdev);



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

end of thread, other threads:[~2015-12-12  2:53 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-12-12  2:09 [PATCH] misc: mic: fix incorrect use of error codes in SCIF DMA driver Eric Biggers
2015-12-12  2:50 ` Sudeep Dutt

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.