All of lore.kernel.org
 help / color / mirror / Atom feed
* [patch] bluetooth: hci_ll: clean up types a bit
@ 2011-09-26  6:14 ` Dan Carpenter
  0 siblings, 0 replies; 6+ messages in thread
From: Dan Carpenter @ 2011-09-26  6:14 UTC (permalink / raw)
  To: Marcel Holtmann; +Cc: Gustavo F. Padovan, linux-bluetooth, kernel-janitors

I'm doing an audit of places where min_t() casting truncates a
variable such as:
	len = min_t(unsigned int, ll->rx_count, count);
Here ll->rx_count is unsigned long, but we cast it to unsigned int
and lose the significant bits.

Looking at the code ->rx_count is never more than 256 so we could
just make it an int.

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

diff --git a/drivers/bluetooth/hci_ll.c b/drivers/bluetooth/hci_ll.c
index 7e4b435..7bb1d8e 100644
--- a/drivers/bluetooth/hci_ll.c
+++ b/drivers/bluetooth/hci_ll.c
@@ -78,7 +78,7 @@ struct hcill_cmd {
 
 struct ll_struct {
 	unsigned long rx_state;
-	unsigned long rx_count;
+	unsigned int rx_count;
 	struct sk_buff *rx_skb;
 	struct sk_buff_head txq;
 	spinlock_t hcill_lock;		/* HCILL state lock	*/
@@ -346,7 +346,7 @@ static int ll_enqueue(struct hci_uart *hu, struct sk_buff *skb)
 	return 0;
 }
 
-static inline int ll_check_data_len(struct ll_struct *ll, int len)
+static inline int ll_check_data_len(struct ll_struct *ll, unsigned int len)
 {
 	register int room = skb_tailroom(ll->rx_skb);
 
@@ -380,7 +380,7 @@ static int ll_recv(struct hci_uart *hu, void *data, int count)
 	struct hci_sco_hdr   *sh;
 	register int len, type, dlen;
 
-	BT_DBG("hu %p count %d rx_state %ld rx_count %ld", hu, count, ll->rx_state, ll->rx_count);
+	BT_DBG("hu %p count %d rx_state %ld rx_count %u", hu, count, ll->rx_state, ll->rx_count);
 
 	ptr = data;
 	while (count) {

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

* [patch] bluetooth: hci_ll: clean up types a bit
@ 2011-09-26  6:14 ` Dan Carpenter
  0 siblings, 0 replies; 6+ messages in thread
From: Dan Carpenter @ 2011-09-26  6:14 UTC (permalink / raw)
  To: Marcel Holtmann; +Cc: Gustavo F. Padovan, linux-bluetooth, kernel-janitors

I'm doing an audit of places where min_t() casting truncates a
variable such as:
	len = min_t(unsigned int, ll->rx_count, count);
Here ll->rx_count is unsigned long, but we cast it to unsigned int
and lose the significant bits.

Looking at the code ->rx_count is never more than 256 so we could
just make it an int.

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

diff --git a/drivers/bluetooth/hci_ll.c b/drivers/bluetooth/hci_ll.c
index 7e4b435..7bb1d8e 100644
--- a/drivers/bluetooth/hci_ll.c
+++ b/drivers/bluetooth/hci_ll.c
@@ -78,7 +78,7 @@ struct hcill_cmd {
 
 struct ll_struct {
 	unsigned long rx_state;
-	unsigned long rx_count;
+	unsigned int rx_count;
 	struct sk_buff *rx_skb;
 	struct sk_buff_head txq;
 	spinlock_t hcill_lock;		/* HCILL state lock	*/
@@ -346,7 +346,7 @@ static int ll_enqueue(struct hci_uart *hu, struct sk_buff *skb)
 	return 0;
 }
 
-static inline int ll_check_data_len(struct ll_struct *ll, int len)
+static inline int ll_check_data_len(struct ll_struct *ll, unsigned int len)
 {
 	register int room = skb_tailroom(ll->rx_skb);
 
@@ -380,7 +380,7 @@ static int ll_recv(struct hci_uart *hu, void *data, int count)
 	struct hci_sco_hdr   *sh;
 	register int len, type, dlen;
 
-	BT_DBG("hu %p count %d rx_state %ld rx_count %ld", hu, count, ll->rx_state, ll->rx_count);
+	BT_DBG("hu %p count %d rx_state %ld rx_count %u", hu, count, ll->rx_state, ll->rx_count);
 
 	ptr = data;
 	while (count) {

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

* Re: [patch] bluetooth: hci_ll: clean up types a bit
  2011-09-26  6:14 ` Dan Carpenter
@ 2011-09-29 19:28   ` Gustavo Padovan
  -1 siblings, 0 replies; 6+ messages in thread
From: Gustavo Padovan @ 2011-09-29 19:28 UTC (permalink / raw)
  To: Dan Carpenter; +Cc: Marcel Holtmann, linux-bluetooth, kernel-janitors

Hi Dan,

* Dan Carpenter <dan.carpenter@oracle.com> [2011-09-26 09:14:12 +0300]:

> I'm doing an audit of places where min_t() casting truncates a
> variable such as:
> 	len = min_t(unsigned int, ll->rx_count, count);
> Here ll->rx_count is unsigned long, but we cast it to unsigned int
> and lose the significant bits.
> 
> Looking at the code ->rx_count is never more than 256 so we could
> just make it an int.

Where is this 256 maximum? I'm not seeing it?

	Gustavo

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

* Re: [patch] bluetooth: hci_ll: clean up types a bit
@ 2011-09-29 19:28   ` Gustavo Padovan
  0 siblings, 0 replies; 6+ messages in thread
From: Gustavo Padovan @ 2011-09-29 19:28 UTC (permalink / raw)
  To: Dan Carpenter; +Cc: Marcel Holtmann, linux-bluetooth, kernel-janitors

Hi Dan,

* Dan Carpenter <dan.carpenter@oracle.com> [2011-09-26 09:14:12 +0300]:

> I'm doing an audit of places where min_t() casting truncates a
> variable such as:
> 	len = min_t(unsigned int, ll->rx_count, count);
> Here ll->rx_count is unsigned long, but we cast it to unsigned int
> and lose the significant bits.
> 
> Looking at the code ->rx_count is never more than 256 so we could
> just make it an int.

Where is this 256 maximum? I'm not seeing it?

	Gustavo

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

* Re: [patch] bluetooth: hci_ll: clean up types a bit
  2011-09-29 19:28   ` Gustavo Padovan
@ 2011-09-29 20:50     ` Dan Carpenter
  -1 siblings, 0 replies; 6+ messages in thread
From: Dan Carpenter @ 2011-09-29 20:50 UTC (permalink / raw)
  To: Marcel Holtmann, linux-bluetooth, kernel-janitors

On Thu, Sep 29, 2011 at 04:28:47PM -0300, Gustavo Padovan wrote:
> Hi Dan,
> 
> * Dan Carpenter <dan.carpenter@oracle.com> [2011-09-26 09:14:12 +0300]:
> 
> > I'm doing an audit of places where min_t() casting truncates a
> > variable such as:
> > 	len = min_t(unsigned int, ll->rx_count, count);
> > Here ll->rx_count is unsigned long, but we cast it to unsigned int
> > and lose the significant bits.
> > 
> > Looking at the code ->rx_count is never more than 256 so we could
> > just make it an int.
> 
> Where is this 256 maximum? I'm not seeing it?
> 

I'm sorry for this, I was wrong.  I'm not sure where I got that...
I can see at least one place where it goes up to USHRT_MAX in
the case of HCILL_W4_ACL_HDR.

I still think the patch is basically correct, but let me take another
look and resend with an updated commit message.

regards,
dan carpenter

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

* Re: [patch] bluetooth: hci_ll: clean up types a bit
@ 2011-09-29 20:50     ` Dan Carpenter
  0 siblings, 0 replies; 6+ messages in thread
From: Dan Carpenter @ 2011-09-29 20:50 UTC (permalink / raw)
  To: Marcel Holtmann, linux-bluetooth, kernel-janitors

On Thu, Sep 29, 2011 at 04:28:47PM -0300, Gustavo Padovan wrote:
> Hi Dan,
> 
> * Dan Carpenter <dan.carpenter@oracle.com> [2011-09-26 09:14:12 +0300]:
> 
> > I'm doing an audit of places where min_t() casting truncates a
> > variable such as:
> > 	len = min_t(unsigned int, ll->rx_count, count);
> > Here ll->rx_count is unsigned long, but we cast it to unsigned int
> > and lose the significant bits.
> > 
> > Looking at the code ->rx_count is never more than 256 so we could
> > just make it an int.
> 
> Where is this 256 maximum? I'm not seeing it?
> 

I'm sorry for this, I was wrong.  I'm not sure where I got that...
I can see at least one place where it goes up to USHRT_MAX in
the case of HCILL_W4_ACL_HDR.

I still think the patch is basically correct, but let me take another
look and resend with an updated commit message.

regards,
dan carpenter


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

end of thread, other threads:[~2011-09-29 20:50 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-09-26  6:14 [patch] bluetooth: hci_ll: clean up types a bit Dan Carpenter
2011-09-26  6:14 ` Dan Carpenter
2011-09-29 19:28 ` Gustavo Padovan
2011-09-29 19:28   ` Gustavo Padovan
2011-09-29 20:50   ` Dan Carpenter
2011-09-29 20:50     ` 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.