public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] bluetooth: kill redundant NULL checks and casts before kfree
@ 2005-05-10 19:05 Jesper Juhl
  2005-05-10 19:28 ` Alexey Dobriyan
  0 siblings, 1 reply; 4+ messages in thread
From: Jesper Juhl @ 2005-05-10 19:05 UTC (permalink / raw)
  To: Marcel Holtmann; +Cc: bluez-devel, Maxim Krasnyansky, linux-kernel

(please keep me on CC when replying)


There's no need to check for NULL before calling kfree() on a pointer, and 
since kfree() takes a void* argument there's no need to cast pointers to 
other types before passing them to kfree().
This patch cleans that up in drivers/bluetooth/

Please apply.


Signed-off-by: Jesper Juhl <juhl-lkml@dif.dk>
---

 drivers/bluetooth/bpa10x.c   |    7 ++-----
 drivers/bluetooth/hci_usb.c  |    6 ++----
 drivers/bluetooth/hci_vhci.c |    8 +++-----
 3 files changed, 7 insertions(+), 14 deletions(-)

diff -upr linux-2.6.12-rc3-mm3-orig/drivers/bluetooth/bpa10x.c linux-2.6.12-rc3-mm3/drivers/bluetooth/bpa10x.c
--- linux-2.6.12-rc3-mm3-orig/drivers/bluetooth/bpa10x.c	2005-03-02 08:38:17.000000000 +0100
+++ linux-2.6.12-rc3-mm3/drivers/bluetooth/bpa10x.c	2005-05-10 20:53:56.000000000 +0200
@@ -367,11 +367,8 @@ static inline void bpa10x_free_urb(struc
 	if (!urb)
 		return;
 
-	if (urb->setup_packet)
-		kfree(urb->setup_packet);
-
-	if (urb->transfer_buffer)
-		kfree(urb->transfer_buffer);
+	kfree(urb->setup_packet);
+	kfree(urb->transfer_buffer);
 
 	usb_free_urb(urb);
 }
diff -upr linux-2.6.12-rc3-mm3-orig/drivers/bluetooth/hci_usb.c linux-2.6.12-rc3-mm3/drivers/bluetooth/hci_usb.c
--- linux-2.6.12-rc3-mm3-orig/drivers/bluetooth/hci_usb.c	2005-04-30 18:24:53.000000000 +0200
+++ linux-2.6.12-rc3-mm3/drivers/bluetooth/hci_usb.c	2005-05-10 20:56:17.000000000 +0200
@@ -387,10 +387,8 @@ static void hci_usb_unlink_urbs(struct h
 			urb = &_urb->urb;
 			BT_DBG("%s freeing _urb %p type %d urb %p",
 					husb->hdev->name, _urb, _urb->type, urb);
-			if (urb->setup_packet)
-				kfree(urb->setup_packet);
-			if (urb->transfer_buffer)
-				kfree(urb->transfer_buffer);
+			kfree(urb->setup_packet);
+			kfree(urb->transfer_buffer);
 			_urb_free(_urb);
 		}
 
diff -upr linux-2.6.12-rc3-mm3-orig/drivers/bluetooth/hci_vhci.c linux-2.6.12-rc3-mm3/drivers/bluetooth/hci_vhci.c
--- linux-2.6.12-rc3-mm3-orig/drivers/bluetooth/hci_vhci.c	2005-04-30 18:24:53.000000000 +0200
+++ linux-2.6.12-rc3-mm3/drivers/bluetooth/hci_vhci.c	2005-05-10 20:58:23.000000000 +0200
@@ -78,12 +78,10 @@ static int hci_vhci_close(struct hci_dev
 
 static void hci_vhci_destruct(struct hci_dev *hdev)
 {
-	struct hci_vhci_struct *vhci;
+	if (!hdev)
+		return;
 
-	if (!hdev) return;
-
-	vhci = (struct hci_vhci_struct *) hdev->driver_data;
-	kfree(vhci);
+	kfree(hdev->driver_data)
 }
 
 static int hci_vhci_send_frame(struct sk_buff *skb)




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

* Re: [PATCH] bluetooth: kill redundant NULL checks and casts before kfree
  2005-05-10 19:05 [PATCH] bluetooth: kill redundant NULL checks and casts before kfree Jesper Juhl
@ 2005-05-10 19:28 ` Alexey Dobriyan
  2005-05-10 19:49   ` Jesper Juhl
  0 siblings, 1 reply; 4+ messages in thread
From: Alexey Dobriyan @ 2005-05-10 19:28 UTC (permalink / raw)
  To: Jesper Juhl; +Cc: Marcel Holtmann, bluez-devel, Maxim Krasnyansky, linux-kernel

On Tuesday 10 May 2005 23:05, Jesper Juhl wrote:

> There's no need to check for NULL before calling kfree() on a pointer, and
> since kfree() takes a void* argument there's no need to cast pointers to
> other types before passing them to kfree().

> +	kfree(hdev->driver_data)	

This won't compile.

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

* Re: [PATCH] bluetooth: kill redundant NULL checks and casts before kfree
  2005-05-10 19:28 ` Alexey Dobriyan
@ 2005-05-10 19:49   ` Jesper Juhl
  2005-05-11 10:55     ` Marcel Holtmann
  0 siblings, 1 reply; 4+ messages in thread
From: Jesper Juhl @ 2005-05-10 19:49 UTC (permalink / raw)
  To: Alexey Dobriyan
  Cc: Marcel Holtmann, bluez-devel, Maxim Krasnyansky, linux-kernel

On Tue, 10 May 2005, Alexey Dobriyan wrote:

> On Tuesday 10 May 2005 23:05, Jesper Juhl wrote:
> 
> > There's no need to check for NULL before calling kfree() on a pointer, and
> > since kfree() takes a void* argument there's no need to cast pointers to
> > other types before passing them to kfree().
> 
> > +	kfree(hdev->driver_data)	
> 
> This won't compile.
> 
Ouch. You are right.
I usually compile test patches, but I have to admit I didn't this time. 
Sorry about that. Fixed patch below.


Signed-off-by: Jesper Juhl <juhl-lkml@dif.dk>
--- 

diff -upr linux-2.6.12-rc3-mm3-orig/drivers/bluetooth/bpa10x.c linux-2.6.12-rc3-mm3/drivers/bluetooth/bpa10x.c
--- linux-2.6.12-rc3-mm3-orig/drivers/bluetooth/bpa10x.c	2005-03-02 08:38:17.000000000 +0100
+++ linux-2.6.12-rc3-mm3/drivers/bluetooth/bpa10x.c	2005-05-10 20:53:56.000000000 +0200
@@ -367,11 +367,8 @@ static inline void bpa10x_free_urb(struc
 	if (!urb)
 		return;
 
-	if (urb->setup_packet)
-		kfree(urb->setup_packet);
-
-	if (urb->transfer_buffer)
-		kfree(urb->transfer_buffer);
+	kfree(urb->setup_packet);
+	kfree(urb->transfer_buffer);
 
 	usb_free_urb(urb);
 }
diff -upr linux-2.6.12-rc3-mm3-orig/drivers/bluetooth/hci_usb.c linux-2.6.12-rc3-mm3/drivers/bluetooth/hci_usb.c
--- linux-2.6.12-rc3-mm3-orig/drivers/bluetooth/hci_usb.c	2005-04-30 18:24:53.000000000 +0200
+++ linux-2.6.12-rc3-mm3/drivers/bluetooth/hci_usb.c	2005-05-10 20:56:17.000000000 +0200
@@ -387,10 +387,8 @@ static void hci_usb_unlink_urbs(struct h
 			urb = &_urb->urb;
 			BT_DBG("%s freeing _urb %p type %d urb %p",
 					husb->hdev->name, _urb, _urb->type, urb);
-			if (urb->setup_packet)
-				kfree(urb->setup_packet);
-			if (urb->transfer_buffer)
-				kfree(urb->transfer_buffer);
+			kfree(urb->setup_packet);
+			kfree(urb->transfer_buffer);
 			_urb_free(_urb);
 		}
 
diff -upr linux-2.6.12-rc3-mm3-orig/drivers/bluetooth/hci_vhci.c linux-2.6.12-rc3-mm3/drivers/bluetooth/hci_vhci.c
--- linux-2.6.12-rc3-mm3-orig/drivers/bluetooth/hci_vhci.c	2005-04-30 18:24:53.000000000 +0200
+++ linux-2.6.12-rc3-mm3/drivers/bluetooth/hci_vhci.c	2005-05-10 21:46:48.000000000 +0200
@@ -78,12 +78,10 @@ static int hci_vhci_close(struct hci_dev
 
 static void hci_vhci_destruct(struct hci_dev *hdev)
 {
-	struct hci_vhci_struct *vhci;
+	if (!hdev)
+		return;
 
-	if (!hdev) return;
-
-	vhci = (struct hci_vhci_struct *) hdev->driver_data;
-	kfree(vhci);
+	kfree(hdev->driver_data);
 }
 
 static int hci_vhci_send_frame(struct sk_buff *skb)



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

* Re: [PATCH] bluetooth: kill redundant NULL checks and casts before kfree
  2005-05-10 19:49   ` Jesper Juhl
@ 2005-05-11 10:55     ` Marcel Holtmann
  0 siblings, 0 replies; 4+ messages in thread
From: Marcel Holtmann @ 2005-05-11 10:55 UTC (permalink / raw)
  To: Jesper Juhl; +Cc: Alexey Dobriyan, bluez-devel, Maxim Krasnyansky, linux-kernel

Hi Jesper,

> > > There's no need to check for NULL before calling kfree() on a pointer, and
> > > since kfree() takes a void* argument there's no need to cast pointers to
> > > other types before passing them to kfree().
> > 
> > > +	kfree(hdev->driver_data)	
> > 
> > This won't compile.
> > 
> Ouch. You are right.
> I usually compile test patches, but I have to admit I didn't this time. 
> Sorry about that. Fixed patch below.

the hci_vhci.c change is not needed, because I have a pending update for
that driver that already fixes this. The other two hunks are in my tree
now.

Regards

Marcel



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

end of thread, other threads:[~2005-05-11 10:55 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-05-10 19:05 [PATCH] bluetooth: kill redundant NULL checks and casts before kfree Jesper Juhl
2005-05-10 19:28 ` Alexey Dobriyan
2005-05-10 19:49   ` Jesper Juhl
2005-05-11 10:55     ` Marcel Holtmann

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox