linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] dma: pl330: fix a couple of compilation warnings
@ 2012-04-08 21:18 Olof Johansson
  2012-04-08 21:40 ` Joe Perches
  2012-04-08 23:26 ` [PATCH v2] " Olof Johansson
  0 siblings, 2 replies; 6+ messages in thread
From: Olof Johansson @ 2012-04-08 21:18 UTC (permalink / raw)
  To: Vinod Koul, Dan Williams
  Cc: linux-kernel, Boojin Kim, linux-arm-kernel, Olof Johansson

Move a couple of tests and do a minor refactor to avoid:

drivers/dma/pl330.c: In function 'pl330_probe':
drivers/dma/pl330.c:2929:215: warning: comparison of distinct pointer types lacks a cast [enabled by default]
drivers/dma/pl330.c: In function 'pl330_tasklet':
drivers/dma/pl330.c:2250:8: warning: 'pch' may be used uninitialized in this function [-Wuninitialized]
drivers/dma/pl330.c:2228:25: note: 'pch' was declared here
drivers/dma/pl330.c:2277:130: warning: 'pch' may be used uninitialized in this function [-Wuninitialized]
drivers/dma/pl330.c:2260:25: note: 'pch' was declared here

Signed-off-by: Olof Johansson <olof@lixom.net>
---
 drivers/dma/pl330.c |   23 +++++++++++++----------
 1 file changed, 13 insertions(+), 10 deletions(-)

diff --git a/drivers/dma/pl330.c b/drivers/dma/pl330.c
index 282caf11..ee0de4b 100644
--- a/drivers/dma/pl330.c
+++ b/drivers/dma/pl330.c
@@ -2225,12 +2225,9 @@ static inline void free_desc_list(struct list_head *list)
 {
 	struct dma_pl330_dmac *pdmac;
 	struct dma_pl330_desc *desc;
-	struct dma_pl330_chan *pch;
+	struct dma_pl330_chan *pch = NULL;
 	unsigned long flags;
 
-	if (list_empty(list))
-		return;
-
 	/* Finish off the work list */
 	list_for_each_entry(desc, list, node) {
 		dma_async_tx_callback callback;
@@ -2247,6 +2244,10 @@ static inline void free_desc_list(struct list_head *list)
 		desc->pchan = NULL;
 	}
 
+	/* pch will be unset if list was empty */
+	if (!pch)
+		return;
+
 	pdmac = pch->dmac;
 
 	spin_lock_irqsave(&pdmac->pool_lock, flags);
@@ -2257,12 +2258,9 @@ static inline void free_desc_list(struct list_head *list)
 static inline void handle_cyclic_desc_list(struct list_head *list)
 {
 	struct dma_pl330_desc *desc;
-	struct dma_pl330_chan *pch;
+	struct dma_pl330_chan *pch = NULL;
 	unsigned long flags;
 
-	if (list_empty(list))
-		return;
-
 	list_for_each_entry(desc, list, node) {
 		dma_async_tx_callback callback;
 
@@ -2274,6 +2272,10 @@ static inline void handle_cyclic_desc_list(struct list_head *list)
 			callback(desc->txd.callback_param);
 	}
 
+	/* pch will be unset if list was empty */
+	if (!pch)
+		return;
+
 	spin_lock_irqsave(&pch->lock, flags);
 	list_splice_tail_init(list, &pch->work_list);
 	spin_unlock_irqrestore(&pch->lock, flags);
@@ -2926,8 +2928,9 @@ pl330_probe(struct amba_device *adev, const struct amba_id *id)
 	INIT_LIST_HEAD(&pd->channels);
 
 	/* Initialize channel parameters */
-	num_chan = max(pdat ? pdat->nr_valid_peri : (u8)pi->pcfg.num_peri,
-			(u8)pi->pcfg.num_chan);
+	num_chan = max_t(int, pdat ? pdat->nr_valid_peri :
+				     pi->pcfg.num_peri,
+			      pi->pcfg.num_chan);
 	pdmac->peripherals = kzalloc(num_chan * sizeof(*pch), GFP_KERNEL);
 
 	for (i = 0; i < num_chan; i++) {
-- 
1.7.9.2.359.gebfc2


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

* Re: [PATCH] dma: pl330: fix a couple of compilation warnings
  2012-04-08 21:18 [PATCH] dma: pl330: fix a couple of compilation warnings Olof Johansson
@ 2012-04-08 21:40 ` Joe Perches
  2012-04-08 23:24   ` Olof Johansson
  2012-04-08 23:26 ` [PATCH v2] " Olof Johansson
  1 sibling, 1 reply; 6+ messages in thread
From: Joe Perches @ 2012-04-08 21:40 UTC (permalink / raw)
  To: Olof Johansson
  Cc: Vinod Koul, Dan Williams, linux-kernel, Boojin Kim, linux-arm-kernel

On Sun, 2012-04-08 at 14:18 -0700, Olof Johansson wrote:
> Move a couple of tests and do a minor refactor to avoid:
[]
> diff --git a/drivers/dma/pl330.c b/drivers/dma/pl330.c
[]
> @@ -2926,8 +2928,9 @@ pl330_probe(struct amba_device *adev, const struct amba_id *id)
>  	INIT_LIST_HEAD(&pd->channels);
>  
>  	/* Initialize channel parameters */
> -	num_chan = max(pdat ? pdat->nr_valid_peri : (u8)pi->pcfg.num_peri,
> -			(u8)pi->pcfg.num_chan);
> +	num_chan = max_t(int, pdat ? pdat->nr_valid_peri :
> +				     pi->pcfg.num_peri,
> +			      pi->pcfg.num_chan);
>  	pdmac->peripherals = kzalloc(num_chan * sizeof(*pch), GFP_KERNEL);

Few trivial things:

There's no error checking for a malloc failure
This should probably be kcalloc
The alignment here is not nice

Maybe:

	num_chan = max_t(size_t, pdat ? pdat->nr_valid_peri : pi->pcfg.num_peri,
			 pi->pcfg.num_chan);
	pdmac->peripherals = kcalloc(num_chan, sizeof(*pch), GFP_KERNEL);
	if (!pdmac->peripherals)
		goto some_err;



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

* Re: [PATCH] dma: pl330: fix a couple of compilation warnings
  2012-04-08 21:40 ` Joe Perches
@ 2012-04-08 23:24   ` Olof Johansson
  2012-04-09  5:02     ` Joe Perches
  0 siblings, 1 reply; 6+ messages in thread
From: Olof Johansson @ 2012-04-08 23:24 UTC (permalink / raw)
  To: Joe Perches
  Cc: Vinod Koul, Dan Williams, linux-kernel, Boojin Kim, linux-arm-kernel

On Sun, Apr 8, 2012 at 2:40 PM, Joe Perches <joe@perches.com> wrote:
> On Sun, 2012-04-08 at 14:18 -0700, Olof Johansson wrote:
>> Move a couple of tests and do a minor refactor to avoid:
> []
>> diff --git a/drivers/dma/pl330.c b/drivers/dma/pl330.c
> []
>> @@ -2926,8 +2928,9 @@ pl330_probe(struct amba_device *adev, const struct amba_id *id)
>>       INIT_LIST_HEAD(&pd->channels);
>>
>>       /* Initialize channel parameters */
>> -     num_chan = max(pdat ? pdat->nr_valid_peri : (u8)pi->pcfg.num_peri,
>> -                     (u8)pi->pcfg.num_chan);
>> +     num_chan = max_t(int, pdat ? pdat->nr_valid_peri :
>> +                                  pi->pcfg.num_peri,
>> +                           pi->pcfg.num_chan);
>>       pdmac->peripherals = kzalloc(num_chan * sizeof(*pch), GFP_KERNEL);
>
> Few trivial things:
>
> There's no error checking for a malloc failure
> This should probably be kcalloc

Yes, this driver could do with further cleanups, congratulations on
your observations.

All of that is completely unrelated to this patch. Feel free to submit
your own changes to clean up the driver further.

> The alignment here is not nice

Bikeshed much? Let's just remove the ? : instead then. New patch shortly.


-Olof

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

* [PATCH v2] dma: pl330: fix a couple of compilation warnings
  2012-04-08 21:18 [PATCH] dma: pl330: fix a couple of compilation warnings Olof Johansson
  2012-04-08 21:40 ` Joe Perches
@ 2012-04-08 23:26 ` Olof Johansson
  2012-04-25  9:37   ` Vinod Koul
  1 sibling, 1 reply; 6+ messages in thread
From: Olof Johansson @ 2012-04-08 23:26 UTC (permalink / raw)
  To: Vinod Koul, Dan Williams
  Cc: linux-kernel, Boojin Kim, linux-arm-kernel, Olof Johansson

Move a couple of tests and do a minor refactor to avoid:

drivers/dma/pl330.c: In function 'pl330_probe':
drivers/dma/pl330.c:2929:215: warning: comparison of distinct pointer types lacks a cast [enabled by default]
drivers/dma/pl330.c: In function 'pl330_tasklet':
drivers/dma/pl330.c:2250:8: warning: 'pch' may be used uninitialized in this function [-Wuninitialized]
drivers/dma/pl330.c:2228:25: note: 'pch' was declared here
drivers/dma/pl330.c:2277:130: warning: 'pch' may be used uninitialized in this function [-Wuninitialized]
drivers/dma/pl330.c:2260:25: note: 'pch' was declared here

Signed-off-by: Olof Johansson <olof@lixom.net>
---
 drivers/dma/pl330.c |   25 +++++++++++++++----------
 1 file changed, 15 insertions(+), 10 deletions(-)

diff --git a/drivers/dma/pl330.c b/drivers/dma/pl330.c
index 282caf11..2ee6e23 100644
--- a/drivers/dma/pl330.c
+++ b/drivers/dma/pl330.c
@@ -2225,12 +2225,9 @@ static inline void free_desc_list(struct list_head *list)
 {
 	struct dma_pl330_dmac *pdmac;
 	struct dma_pl330_desc *desc;
-	struct dma_pl330_chan *pch;
+	struct dma_pl330_chan *pch = NULL;
 	unsigned long flags;
 
-	if (list_empty(list))
-		return;
-
 	/* Finish off the work list */
 	list_for_each_entry(desc, list, node) {
 		dma_async_tx_callback callback;
@@ -2247,6 +2244,10 @@ static inline void free_desc_list(struct list_head *list)
 		desc->pchan = NULL;
 	}
 
+	/* pch will be unset if list was empty */
+	if (!pch)
+		return;
+
 	pdmac = pch->dmac;
 
 	spin_lock_irqsave(&pdmac->pool_lock, flags);
@@ -2257,12 +2258,9 @@ static inline void free_desc_list(struct list_head *list)
 static inline void handle_cyclic_desc_list(struct list_head *list)
 {
 	struct dma_pl330_desc *desc;
-	struct dma_pl330_chan *pch;
+	struct dma_pl330_chan *pch = NULL;
 	unsigned long flags;
 
-	if (list_empty(list))
-		return;
-
 	list_for_each_entry(desc, list, node) {
 		dma_async_tx_callback callback;
 
@@ -2274,6 +2272,10 @@ static inline void handle_cyclic_desc_list(struct list_head *list)
 			callback(desc->txd.callback_param);
 	}
 
+	/* pch will be unset if list was empty */
+	if (!pch)
+		return;
+
 	spin_lock_irqsave(&pch->lock, flags);
 	list_splice_tail_init(list, &pch->work_list);
 	spin_unlock_irqrestore(&pch->lock, flags);
@@ -2926,8 +2928,11 @@ pl330_probe(struct amba_device *adev, const struct amba_id *id)
 	INIT_LIST_HEAD(&pd->channels);
 
 	/* Initialize channel parameters */
-	num_chan = max(pdat ? pdat->nr_valid_peri : (u8)pi->pcfg.num_peri,
-			(u8)pi->pcfg.num_chan);
+	if (pdat)
+		num_chan = max_t(int, pdat->nr_valid_peri, pi->pcfg.num_chan);
+	else
+		num_chan = max_t(int, pi->pcfg.num_peri, pi->pcfg.num_chan);
+
 	pdmac->peripherals = kzalloc(num_chan * sizeof(*pch), GFP_KERNEL);
 
 	for (i = 0; i < num_chan; i++) {
-- 
1.7.9.2.359.gebfc2


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

* Re: [PATCH] dma: pl330: fix a couple of compilation warnings
  2012-04-08 23:24   ` Olof Johansson
@ 2012-04-09  5:02     ` Joe Perches
  0 siblings, 0 replies; 6+ messages in thread
From: Joe Perches @ 2012-04-09  5:02 UTC (permalink / raw)
  To: Olof Johansson
  Cc: Vinod Koul, Dan Williams, linux-kernel, Boojin Kim, linux-arm-kernel

On Sun, 2012-04-08 at 16:24 -0700, Olof Johansson wrote:
> On Sun, Apr 8, 2012 at 2:40 PM, Joe Perches <joe@perches.com> wrote:
> > On Sun, 2012-04-08 at 14:18 -0700, Olof Johansson wrote:
> >> Move a couple of tests and do a minor refactor to avoid:
> > []
> >> diff --git a/drivers/dma/pl330.c b/drivers/dma/pl330.c
> > []
> >> @@ -2926,8 +2928,9 @@ pl330_probe(struct amba_device *adev, const struct amba_id *id)
> >>       INIT_LIST_HEAD(&pd->channels);
> >>
> >>       /* Initialize channel parameters */
> >> -     num_chan = max(pdat ? pdat->nr_valid_peri : (u8)pi->pcfg.num_peri,
> >> -                     (u8)pi->pcfg.num_chan);
> >> +     num_chan = max_t(int, pdat ? pdat->nr_valid_peri :
> >> +                                  pi->pcfg.num_peri,
> >> +                           pi->pcfg.num_chan);
> >>       pdmac->peripherals = kzalloc(num_chan * sizeof(*pch), GFP_KERNEL);
> >
> > Few trivial things:
> >
> > There's no error checking for a malloc failure
> > This should probably be kcalloc
> 
> Yes, this driver could do with further cleanups, congratulations on
> your observations.
> 
> All of that is completely unrelated to this patch. Feel free to submit
> your own changes to clean up the driver further.

No thanks.  It's adjacent to the lines you modify
which is the only reason I noticed.  You might
also notice any patch I submit against the current
tree would conflict with your changes.

It'd be better if you actually fix problems with
the code and not simply make compiler warnings be
silenced when the problem is fundamentally that
the compiler is needs improvements.



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

* Re: [PATCH v2] dma: pl330: fix a couple of compilation warnings
  2012-04-08 23:26 ` [PATCH v2] " Olof Johansson
@ 2012-04-25  9:37   ` Vinod Koul
  0 siblings, 0 replies; 6+ messages in thread
From: Vinod Koul @ 2012-04-25  9:37 UTC (permalink / raw)
  To: Olof Johansson; +Cc: Dan Williams, linux-kernel, linux-arm-kernel, Boojin Kim

On Sun, 2012-04-08 at 16:26 -0700, Olof Johansson wrote:
> Move a couple of tests and do a minor refactor to avoid:
> 
> drivers/dma/pl330.c: In function 'pl330_probe':
> drivers/dma/pl330.c:2929:215: warning: comparison of distinct pointer types lacks a cast [enabled by default]
> drivers/dma/pl330.c: In function 'pl330_tasklet':
> drivers/dma/pl330.c:2250:8: warning: 'pch' may be used uninitialized in this function [-Wuninitialized]
> drivers/dma/pl330.c:2228:25: note: 'pch' was declared here
> drivers/dma/pl330.c:2277:130: warning: 'pch' may be used uninitialized in this function [-Wuninitialized]
> drivers/dma/pl330.c:2260:25: note: 'pch' was declared here
> 
> Signed-off-by: Olof Johansson <olof@lixom.net>
Applied thanks

> ---
>  drivers/dma/pl330.c |   25 +++++++++++++++----------
>  1 file changed, 15 insertions(+), 10 deletions(-)
> 
> diff --git a/drivers/dma/pl330.c b/drivers/dma/pl330.c
> index 282caf11..2ee6e23 100644
> --- a/drivers/dma/pl330.c
> +++ b/drivers/dma/pl330.c
> @@ -2225,12 +2225,9 @@ static inline void free_desc_list(struct list_head *list)
>  {
>  	struct dma_pl330_dmac *pdmac;
>  	struct dma_pl330_desc *desc;
> -	struct dma_pl330_chan *pch;
> +	struct dma_pl330_chan *pch = NULL;
>  	unsigned long flags;
>  
> -	if (list_empty(list))
> -		return;
> -
>  	/* Finish off the work list */
>  	list_for_each_entry(desc, list, node) {
>  		dma_async_tx_callback callback;
> @@ -2247,6 +2244,10 @@ static inline void free_desc_list(struct list_head *list)
>  		desc->pchan = NULL;
>  	}
>  
> +	/* pch will be unset if list was empty */
> +	if (!pch)
> +		return;
> +
>  	pdmac = pch->dmac;
>  
>  	spin_lock_irqsave(&pdmac->pool_lock, flags);
> @@ -2257,12 +2258,9 @@ static inline void free_desc_list(struct list_head *list)
>  static inline void handle_cyclic_desc_list(struct list_head *list)
>  {
>  	struct dma_pl330_desc *desc;
> -	struct dma_pl330_chan *pch;
> +	struct dma_pl330_chan *pch = NULL;
>  	unsigned long flags;
>  
> -	if (list_empty(list))
> -		return;
> -
>  	list_for_each_entry(desc, list, node) {
>  		dma_async_tx_callback callback;
>  
> @@ -2274,6 +2272,10 @@ static inline void handle_cyclic_desc_list(struct list_head *list)
>  			callback(desc->txd.callback_param);
>  	}
>  
> +	/* pch will be unset if list was empty */
> +	if (!pch)
> +		return;
> +
>  	spin_lock_irqsave(&pch->lock, flags);
>  	list_splice_tail_init(list, &pch->work_list);
>  	spin_unlock_irqrestore(&pch->lock, flags);
> @@ -2926,8 +2928,11 @@ pl330_probe(struct amba_device *adev, const struct amba_id *id)
>  	INIT_LIST_HEAD(&pd->channels);
>  
>  	/* Initialize channel parameters */
> -	num_chan = max(pdat ? pdat->nr_valid_peri : (u8)pi->pcfg.num_peri,
> -			(u8)pi->pcfg.num_chan);
> +	if (pdat)
> +		num_chan = max_t(int, pdat->nr_valid_peri, pi->pcfg.num_chan);
> +	else
> +		num_chan = max_t(int, pi->pcfg.num_peri, pi->pcfg.num_chan);
> +
>  	pdmac->peripherals = kzalloc(num_chan * sizeof(*pch), GFP_KERNEL);
>  
>  	for (i = 0; i < num_chan; i++) {


-- 
~Vinod


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

end of thread, other threads:[~2012-04-25  9:41 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-04-08 21:18 [PATCH] dma: pl330: fix a couple of compilation warnings Olof Johansson
2012-04-08 21:40 ` Joe Perches
2012-04-08 23:24   ` Olof Johansson
2012-04-09  5:02     ` Joe Perches
2012-04-08 23:26 ` [PATCH v2] " Olof Johansson
2012-04-25  9:37   ` Vinod Koul

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).