All of lore.kernel.org
 help / color / mirror / Atom feed
* re: rtl2832_sdr: move from staging to media
@ 2015-05-13 11:11 Dan Carpenter
  2015-05-13 15:00 ` Antti Palosaari
  0 siblings, 1 reply; 4+ messages in thread
From: Dan Carpenter @ 2015-05-13 11:11 UTC (permalink / raw)
  To: crope; +Cc: linux-media

Hello Antti Palosaari,

The patch 77bbb2b049c1: "rtl2832_sdr: move from staging to media"
from Jul 15, 2014, leads to the following static checker warning:

	drivers/media/dvb-frontends/rtl2832_sdr.c:1265 rtl2832_sdr_s_ctrl()
	warn: test_bit() bitwise op in bit number

This is harmless but messy.

drivers/media/dvb-frontends/rtl2832_sdr.c
   109  
   110  struct rtl2832_sdr_dev {
   111  #define POWER_ON           (1 << 1)
   112  #define URB_BUF            (1 << 2)

We were supposed to use these to set ->flags on the next line.

   113          unsigned long flags;
   114  
   115          struct platform_device *pdev;
   116  
   117          struct video_device vdev;
   118          struct v4l2_device v4l2_dev;
   119  

[ snip ]

   389                  dev_dbg(&pdev->dev, "alloc buf=%d %p (dma %llu)\n",
   390                          dev->buf_num, dev->buf_list[dev->buf_num],
   391                          (long long)dev->dma_addr[dev->buf_num]);
   392                  dev->flags |= USB_STATE_URB_BUF;
                                      ^^^^^^^^^^^^^^^^^
But we use USB_STATE_URB_BUF (0x1) instead of URB_BUF.

   393          }

[ snip ]

  1263                  c->bandwidth_hz = dev->bandwidth->val;
  1264  
  1265                  if (!test_bit(POWER_ON, &dev->flags))
                                      ^^^^^^^^
The original intent of the code was we test "if (dev->flags & POWER_ON)"
but really what this is doing is "if (dev->flags & (1 << POWER_ON))"
which is fine because we do it consistently, but it's not pretty and it
causes static checkers to complain (and rightfully so).

  1266                          return 0;
  1267  
  1268                  if (fe->ops.tuner_ops.set_params)
  1269                          ret = fe->ops.tuner_ops.set_params(fe);
  1270                  else
  1271                          ret = 0;
  1272                  break;
  1273          default:

regards,
dan carpenter

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

* Re: rtl2832_sdr: move from staging to media
  2015-05-13 11:11 rtl2832_sdr: move from staging to media Dan Carpenter
@ 2015-05-13 15:00 ` Antti Palosaari
  2015-05-14  8:39     ` Dan Carpenter
  0 siblings, 1 reply; 4+ messages in thread
From: Antti Palosaari @ 2015-05-13 15:00 UTC (permalink / raw)
  To: Dan Carpenter; +Cc: linux-media

Moikka!

On 05/13/2015 02:11 PM, Dan Carpenter wrote:
> Hello Antti Palosaari,
>
> The patch 77bbb2b049c1: "rtl2832_sdr: move from staging to media"
> from Jul 15, 2014, leads to the following static checker warning:
>
> 	drivers/media/dvb-frontends/rtl2832_sdr.c:1265 rtl2832_sdr_s_ctrl()
> 	warn: test_bit() bitwise op in bit number
>
> This is harmless but messy.
>
> drivers/media/dvb-frontends/rtl2832_sdr.c
>     109
>     110  struct rtl2832_sdr_dev {
>     111  #define POWER_ON           (1 << 1)
>     112  #define URB_BUF            (1 << 2)
>
> We were supposed to use these to set ->flags on the next line.
>
>     113          unsigned long flags;
>     114
>     115          struct platform_device *pdev;
>     116
>     117          struct video_device vdev;
>     118          struct v4l2_device v4l2_dev;
>     119
>
> [ snip ]
>
>     389                  dev_dbg(&pdev->dev, "alloc buf=%d %p (dma %llu)\n",
>     390                          dev->buf_num, dev->buf_list[dev->buf_num],
>     391                          (long long)dev->dma_addr[dev->buf_num]);
>     392                  dev->flags |= USB_STATE_URB_BUF;
>                                        ^^^^^^^^^^^^^^^^^
> But we use USB_STATE_URB_BUF (0x1) instead of URB_BUF.
>
>     393          }
>
> [ snip ]
>
>    1263                  c->bandwidth_hz = dev->bandwidth->val;
>    1264
>    1265                  if (!test_bit(POWER_ON, &dev->flags))
>                                        ^^^^^^^^
> The original intent of the code was we test "if (dev->flags & POWER_ON)"
> but really what this is doing is "if (dev->flags & (1 << POWER_ON))"
> which is fine because we do it consistently, but it's not pretty and it
> causes static checkers to complain (and rightfully so).
>
>    1266                          return 0;
>    1267
>    1268                  if (fe->ops.tuner_ops.set_params)
>    1269                          ret = fe->ops.tuner_ops.set_params(fe);
>    1270                  else
>    1271                          ret = 0;
>    1272                  break;
>    1273          default:
>

If you wish, you could fix those. Otherwise I will check issues pointed 
and correct. Lets say I will wait at least one week your patch.

[At the some point I am going to rewrote that USB streaming code as I am 
not happy with it. Also I have one device which needs to stream data 
both ways, from device to computer and from computer to device, which 
should be take into account.]

regards
Antti

-- 
http://palosaari.fi/

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

* [patch] [media] rtl2832_sdr: cleanup some set_bit() calls
  2015-05-13 15:00 ` Antti Palosaari
@ 2015-05-14  8:39     ` Dan Carpenter
  0 siblings, 0 replies; 4+ messages in thread
From: Dan Carpenter @ 2015-05-14  8:39 UTC (permalink / raw)
  To: Antti Palosaari; +Cc: Mauro Carvalho Chehab, linux-media, kernel-janitors

This code works fine but static checkers complain.  The test_bit()
function takes the bit number and not a mask.  Then the other issue is
that we were using USB_STATE_URB_BUF which is BIT(0) instead of URB_BUF.
Also we were open coding that instead of using the test/clear/set_bit()
functions.

Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>

diff --git a/drivers/media/dvb-frontends/rtl2832_sdr.c b/drivers/media/dvb-frontends/rtl2832_sdr.c
index 3ff8806..6362c6c 100644
--- a/drivers/media/dvb-frontends/rtl2832_sdr.c
+++ b/drivers/media/dvb-frontends/rtl2832_sdr.c
@@ -108,8 +108,8 @@ struct rtl2832_sdr_frame_buf {
 };
 
 struct rtl2832_sdr_dev {
-#define POWER_ON           (1 << 1)
-#define URB_BUF            (1 << 2)
+#define POWER_ON           0  /* BIT(0) */
+#define URB_BUF            1  /* BIT(1) */
 	unsigned long flags;
 
 	struct platform_device *pdev;
@@ -351,7 +351,7 @@ static int rtl2832_sdr_free_stream_bufs(struct rtl2832_sdr_dev *dev)
 {
 	struct platform_device *pdev = dev->pdev;
 
-	if (dev->flags & USB_STATE_URB_BUF) {
+	if (test_bit(URB_BUF, &dev->flags)) {
 		while (dev->buf_num) {
 			dev->buf_num--;
 			dev_dbg(&pdev->dev, "free buf=%d\n", dev->buf_num);
@@ -360,7 +360,7 @@ static int rtl2832_sdr_free_stream_bufs(struct rtl2832_sdr_dev *dev)
 					  dev->dma_addr[dev->buf_num]);
 		}
 	}
-	dev->flags &= ~USB_STATE_URB_BUF;
+	clear_bit(URB_BUF, &dev->flags);
 
 	return 0;
 }
@@ -389,7 +389,7 @@ static int rtl2832_sdr_alloc_stream_bufs(struct rtl2832_sdr_dev *dev)
 		dev_dbg(&pdev->dev, "alloc buf=%d %p (dma %llu)\n",
 			dev->buf_num, dev->buf_list[dev->buf_num],
 			(long long)dev->dma_addr[dev->buf_num]);
-		dev->flags |= USB_STATE_URB_BUF;
+		set_bit(URB_BUF, &dev->flags);
 	}
 
 	return 0;

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

* [patch] [media] rtl2832_sdr: cleanup some set_bit() calls
@ 2015-05-14  8:39     ` Dan Carpenter
  0 siblings, 0 replies; 4+ messages in thread
From: Dan Carpenter @ 2015-05-14  8:39 UTC (permalink / raw)
  To: Antti Palosaari; +Cc: Mauro Carvalho Chehab, linux-media, kernel-janitors

This code works fine but static checkers complain.  The test_bit()
function takes the bit number and not a mask.  Then the other issue is
that we were using USB_STATE_URB_BUF which is BIT(0) instead of URB_BUF.
Also we were open coding that instead of using the test/clear/set_bit()
functions.

Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>

diff --git a/drivers/media/dvb-frontends/rtl2832_sdr.c b/drivers/media/dvb-frontends/rtl2832_sdr.c
index 3ff8806..6362c6c 100644
--- a/drivers/media/dvb-frontends/rtl2832_sdr.c
+++ b/drivers/media/dvb-frontends/rtl2832_sdr.c
@@ -108,8 +108,8 @@ struct rtl2832_sdr_frame_buf {
 };
 
 struct rtl2832_sdr_dev {
-#define POWER_ON           (1 << 1)
-#define URB_BUF            (1 << 2)
+#define POWER_ON           0  /* BIT(0) */
+#define URB_BUF            1  /* BIT(1) */
 	unsigned long flags;
 
 	struct platform_device *pdev;
@@ -351,7 +351,7 @@ static int rtl2832_sdr_free_stream_bufs(struct rtl2832_sdr_dev *dev)
 {
 	struct platform_device *pdev = dev->pdev;
 
-	if (dev->flags & USB_STATE_URB_BUF) {
+	if (test_bit(URB_BUF, &dev->flags)) {
 		while (dev->buf_num) {
 			dev->buf_num--;
 			dev_dbg(&pdev->dev, "free buf=%d\n", dev->buf_num);
@@ -360,7 +360,7 @@ static int rtl2832_sdr_free_stream_bufs(struct rtl2832_sdr_dev *dev)
 					  dev->dma_addr[dev->buf_num]);
 		}
 	}
-	dev->flags &= ~USB_STATE_URB_BUF;
+	clear_bit(URB_BUF, &dev->flags);
 
 	return 0;
 }
@@ -389,7 +389,7 @@ static int rtl2832_sdr_alloc_stream_bufs(struct rtl2832_sdr_dev *dev)
 		dev_dbg(&pdev->dev, "alloc buf=%d %p (dma %llu)\n",
 			dev->buf_num, dev->buf_list[dev->buf_num],
 			(long long)dev->dma_addr[dev->buf_num]);
-		dev->flags |= USB_STATE_URB_BUF;
+		set_bit(URB_BUF, &dev->flags);
 	}
 
 	return 0;

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

end of thread, other threads:[~2015-05-14  8:39 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-05-13 11:11 rtl2832_sdr: move from staging to media Dan Carpenter
2015-05-13 15:00 ` Antti Palosaari
2015-05-14  8:39   ` [patch] [media] rtl2832_sdr: cleanup some set_bit() calls Dan Carpenter
2015-05-14  8:39     ` Dan Carpenter

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.