Skip to contentSkip to conversation

bluetooth:hicp:Fix error handling in the function hidp_connection_del

PATCH RESEND Superseded Nicholas Krause 2 participants 2 messages Dec 29, 2015 – Jan 8, 2016

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH RESEND 1/1 bluetooth:hicp:Fix error handling in the function hidp_connection_del

This fixes error handling in the function hidp_connection_del to properly check if the internal call to hidp_send_ctrl_message has failed by returning a error code and if so immediately return this error code to the caller of hidp_connection_del to signal that a failed call has occurred that needs to be handled by this function's caller.

---
 net/bluetooth/hidp/core.c | 17 ++++++++++-------
 1 file changed, 10 insertions(+), 7 deletions(-)
net/bluetooth/hidp/core.c +10 -7
index f1a117f..13aa6d0 100644
@@ -1360,6 +1360,7 @@ int hidp_connection_del(struct hidp_conndel_req *req)
 {
 	u32 valid_flags = BIT(HIDP_VIRTUAL_CABLE_UNPLUG);
 	struct hidp_session *session;
+	int err;
 
 	if (req->flags & ~valid_flags)
 		return -EINVAL;
@@ -1368,14 +1369,16 @@ int hidp_connection_del(struct hidp_conndel_req *req)
 	if (!session)
 		return -ENOENT;
 
-	if (req->flags & BIT(HIDP_VIRTUAL_CABLE_UNPLUG))
-		hidp_send_ctrl_message(session,
-				       HIDP_TRANS_HID_CONTROL |
-				         HIDP_CTRL_VIRTUAL_CABLE_UNPLUG,
-				       NULL, 0);
-	else
+	if (req->flags & BIT(HIDP_VIRTUAL_CABLE_UNPLUG)) {
+		err = hidp_send_ctrl_message(session,
+					     HIDP_TRANS_HID_CONTROL |
+					     HIDP_CTRL_VIRTUAL_CABLE_UNPLUG,
+					     NULL, 0);
+		if (err)
+			return err;
+	} else {
 		l2cap_unregister_user(session->conn, &session->user);
-
+	}
 	hidp_session_put(session);
 
 	return 0;
Signature · 1 line
2.1.4
#1 lore raw

Hi

Quoted 31 lines · Nicholas Krause

This fixes error handling in the function hidp_connection_del to properly check if the internal call to hidp_send_ctrl_message has failed by returning a error code and if so immediately return this error code to the caller of hidp_connection_del to signal that a failed call has occurred that needs to be handled by this function's caller.

---
 net/bluetooth/hidp/core.c | 17 ++++++++++-------
 1 file changed, 10 insertions(+), 7 deletions(-)
net/bluetooth/hidp/core.c +1 -3
index f1a117f..13aa6d0 100644
@@ -1360,6 +1360,7 @@ int hidp_connection_del(struct hidp_conndel_req *req)
 {
        u32 valid_flags = BIT(HIDP_VIRTUAL_CABLE_UNPLUG);
        struct hidp_session *session;
+       int err;
 
        if (req->flags & ~valid_flags)
                return -EINVAL;
@@ -1368,14 +1369,16 @@ int hidp_connection_del(struct hidp_conndel_req *req)
        if (!session)
                return -ENOENT;
 
-       if (req->flags & BIT(HIDP_VIRTUAL_CABLE_UNPLUG))
-               hidp_send_ctrl_message(session,
-                                      HIDP_TRANS_HID_CONTROL |

net/bluetooth/hidp/core.c int hidp_connection_del(struct hidp_conndel_req *req) · line 1378

Quoted 10 lines
net/bluetooth/hidp/core.c +7 -3
-                                        HIDP_CTRL_VIRTUAL_CABLE_UNPLUG,
-                                      NULL, 0);
-       else
+       if (req->flags & BIT(HIDP_VIRTUAL_CABLE_UNPLUG)) {
+               err = hidp_send_ctrl_message(session,
+                                            HIDP_TRANS_HID_CONTROL |
+                                            HIDP_CTRL_VIRTUAL_CABLE_UNPLUG,
+                                            NULL, 0);
+               if (err)
+                       return err;

This leaks a reference to 'session'.

net/bluetooth/hidp/core.c int hidp_connection_del(struct hidp_conndel_req *req) · line 1382

Quoted 5 lines
net/bluetooth/hidp/core.c +2 -1
+       } else {
                l2cap_unregister_user(session->conn, &session->user);
-
+       }
        hidp_session_put(session);

I'm not very convinced that this is a good idea. Transmission is handled async, hence all you catch here is OOM. Nothing interesting can be returned, and there's nothing sane the caller can do to handle the error. I'd keep the code as is.

Thanks
David

Quoted 5 lines
net/bluetooth/hidp/core.c +0 -1
        return 0;
--

2.1.4