net/capi: use wait_event_interruptible_timeout()
Subsystems (3)
PATCH 17/39 net/capi: use wait_event_interruptible_timeout()
Hi,
Please consider applying.
Description: Use wait_event_interruptible_timeout() instead of custom wait-queue code. The first replacement is the most complicated as the various return conditions each indicate different things, apparently. The same effects are made after wait_event_interruptible_timeout() returns.
net/bluetooth/cmtp/capi.c +17 -63
@@ -35,6 +35,7 @@#include <linux/socket.h> #include <linux/ioctl.h> #include <linux/file.h> +#include <linux/wait.h> #include <net/sock.h> #include <linux/isdn/capilli.h>
@@ -373,12 +374,11 @@ static void cmtp_reset_ctr(struct capi_cstatic void cmtp_register_appl (struct capi_ctr *ctrl,__u16 appl,capi_register_params *rp) { -DECLARE_WAITQUEUE (wait, current);struct cmtp_session *session = ctrl->driverdata;struct cmtp_application *application; -unsigned long timeo =CMTP_INTEROP_TIMEOUT ;unsigned char buf[8 ];int err =0 , nconn, want = rp->level3cnt; +long ret;BT_DBG ("ctrl %p appl %d level3cnt %d datablkcnt %d datablklen %d" , ctrl, appl, rp->level3cnt, rp->datablkcnt, rp->datablklen);
@@ -407,33 +407,15 @@ static void cmtp_register_appl(struct cacmtp_send_interopmsg (session,CAPI_REQ ,0x0000 , application->msgnum,CAPI_FUNCTION_REGISTER , buf,6 ); -add_wait_queue (&session->wait, &wait); -while (1 ) { -set_current_state (TASK_INTERRUPTIBLE ); - -if (!timeo) { - err = -EAGAIN ; -break ; - } - -if (application->state ==BT_CLOSED ) { - err = -application->err; -break ; - } - -if (application->state ==BT_CONNECTED ) -break ; - -if (signal_pending (current)) { - err = -EINTR ; -break ; - } - - timeo =schedule_timeout (timeo); - } -set_current_state (TASK_RUNNING ); -remove_wait_queue (&session->wait, &wait); - + ret =wait_event_interruptible_timeout (session->wait, + ((application->state ==BT_CLOSED ) || (application->state ==BT_CONNECTED )), +CMTP_INTEROP_TIMEOUT ); +if (!ret) + err = -EAGAIN ; +else if (application->state ==BT_CLOSED ) + err = -application->err; +else if (signal_pending (current)) + err = -EINTR ;if (err) {cmtp_application_del (session, application);return ;
@@ -442,10 +424,8 @@ static void cmtp_register_appl(struct castatic void cmtp_release_appl (struct capi_ctr *ctrl,__u16 appl) { -DECLARE_WAITQUEUE (wait, current);struct cmtp_session *session = ctrl->driverdata;struct cmtp_application *application; -unsigned long timeo =CMTP_INTEROP_TIMEOUT ;BT_DBG ("ctrl %p appl %d" , ctrl, appl);
@@ -460,20 +440,8 @@ static void cmtp_release_appl(struct capcmtp_send_interopmsg (session,CAPI_REQ , application->mapping, application->msgnum,CAPI_FUNCTION_RELEASE ,NULL ,0 ); -add_wait_queue (&session->wait, &wait); -while (timeo) { -set_current_state (TASK_INTERRUPTIBLE ); - -if (application->state ==BT_CLOSED ) -break ; - -if (signal_pending (current)) -break ; - - timeo =schedule_timeout (timeo); - } -set_current_state (TASK_RUNNING ); -remove_wait_queue (&session->wait, &wait); +wait_event_interruptible_timeout (session->wait, (application->state ==BT_CLOSED ), +CMTP_INTEROP_TIMEOUT );cmtp_application_del (session, application); }
@@ -543,8 +511,7 @@ static int cmtp_ctr_read_proc(char *pageint cmtp_attach_device (struct cmtp_session *session) { -DECLARE_WAITQUEUE (wait, current); -unsigned long timeo =CMTP_INTEROP_TIMEOUT ; +long ret;unsigned char buf[4 ];BT_DBG ("session %p" , session);
@@ -554,30 +521,17 @@ int cmtp_attach_device(struct cmtp_sessicmtp_send_interopmsg (session,CAPI_REQ ,0xffff ,CMTP_INITIAL_MSGNUM ,CAPI_FUNCTION_GET_PROFILE , buf,4 ); -add_wait_queue (&session->wait, &wait); -while (timeo) { -set_current_state (TASK_INTERRUPTIBLE ); - -if (session->ncontroller) -break ; - -if (signal_pending (current)) -break ; - - timeo =schedule_timeout (timeo); - } -set_current_state (TASK_RUNNING ); -remove_wait_queue (&session->wait, &wait); + ret =wait_event_interruptible_timeout (session->wait, session->ncontroller, +CMTP_INTEROP_TIMEOUT );BT_INFO ("Found %d CAPI controller(s) on device %s" , session->ncontroller, session->name); -if (!timeo) +if (!ret)return -ETIMEDOUT ;if (!session->ncontroller)return -ENODEV ; -if (session->ncontroller >1 )BT_INFO ("Setting up only CAPI controller 1" );
_______________________________________________
Kernel-janitors mailing list
[email protected]
http://lists.osdl.org/mailman/listinfo/kernel-janitors
Marcel Holtmann
maintainer[KJ] Re: [PATCH 17/39] net/capi: use
Hi Nishanth,
Quoted 4 lines
Description: Use
wait_event_interruptible_timeout()instead of custom wait-queue code. The first replacement is the most complicated as the various return conditions each indicate different things, apparently. The same effects are made afterwait_event_interruptible_timeout()returns.
the first one makes the code look ugly. Remove it and re-submit.
Regards
Marcel
_______________________________________________
Kernel-janitors mailing list
[email protected]
http://lists.osdl.org/mailman/listinfo/kernel-janitors
PATCH 17/39 net/capi: use
Quoted 8 lines · Marcel Holtmann
Hi Nishanth,
Quoted 4 lines
Description: Use
wait_event_interruptible_timeout()instead of custom wait-queue code. The first replacement is the most complicated as the various return conditions each indicate different things, apparently. The same effects are made afterwait_event_interruptible_timeout()returns.the first one makes the code look ugly. Remove it and re-submit.
Thanks for the input. Fixed below.
-Nish
Description: Use wait_event_interruptible_timeout() instead of custom wait-queue code. Remove the now unused variables in both functions.
net/bluetooth/cmtp/capi.c +7 -35
@@ -35,6 +35,7 @@#include <linux/socket.h> #include <linux/ioctl.h> #include <linux/file.h> +#include <linux/wait.h> #include <net/sock.h> #include <linux/isdn/capilli.h>
@@ -442,10 +443,8 @@ static void cmtp_register_appl(struct castatic void cmtp_release_appl (struct capi_ctr *ctrl,__u16 appl) { -DECLARE_WAITQUEUE (wait, current);struct cmtp_session *session = ctrl->driverdata;struct cmtp_application *application; -unsigned long timeo =CMTP_INTEROP_TIMEOUT ;BT_DBG ("ctrl %p appl %d" , ctrl, appl);
@@ -460,20 +459,8 @@ static void cmtp_release_appl(struct capcmtp_send_interopmsg (session,CAPI_REQ , application->mapping, application->msgnum,CAPI_FUNCTION_RELEASE ,NULL ,0 ); -add_wait_queue (&session->wait, &wait); -while (timeo) { -set_current_state (TASK_INTERRUPTIBLE ); - -if (application->state ==BT_CLOSED ) -break ; - -if (signal_pending (current)) -break ; - - timeo =schedule_timeout (timeo); - } -set_current_state (TASK_RUNNING ); -remove_wait_queue (&session->wait, &wait); +wait_event_interruptible_timeout (session->wait, + (application->state ==BT_CLOSED ),CMTP_INTEROP_TIMEOUT );cmtp_application_del (session, application); }
@@ -543,8 +530,6 @@ static int cmtp_ctr_read_proc(char *pageint cmtp_attach_device (struct cmtp_session *session) { -DECLARE_WAITQUEUE (wait, current); -unsigned long timeo =CMTP_INTEROP_TIMEOUT ;unsigned char buf[4 ];BT_DBG ("session %p" , session);
@@ -554,30 +539,17 @@ int cmtp_attach_device(struct cmtp_sessicmtp_send_interopmsg (session,CAPI_REQ ,0xffff ,CMTP_INITIAL_MSGNUM ,CAPI_FUNCTION_GET_PROFILE , buf,4 ); -add_wait_queue (&session->wait, &wait); -while (timeo) { -set_current_state (TASK_INTERRUPTIBLE ); - -if (session->ncontroller) -break ; - -if (signal_pending (current)) -break ; - - timeo =schedule_timeout (timeo); - } -set_current_state (TASK_RUNNING ); -remove_wait_queue (&session->wait, &wait); - + ret =wait_event_interruptible_timeout (session->wait, + session->ncontroller,CMTP_INTEROP_TIMEOUT ); +BT_INFO ("Found %d CAPI controller(s) on device %s" , session->ncontroller, session->name); -if (!timeo) +if (!ret)return -ETIMEDOUT ;if (!session->ncontroller)return -ENODEV ; -if (session->ncontroller >1 )BT_INFO ("Setting up only CAPI controller 1" );
_______________________________________________
Kernel-janitors mailing list
[email protected]
http://lists.osdl.org/mailman/listinfo/kernel-janitors