[char-misc-next 2/3] mei: bus: stop wait for read during cl state transition

2013-09-02 Thread Tomas Winkler
Bus layer omitted check for client state transition while waiting
for read completion
The client state transition may occur for example as result
of firmware initiated reset

Add mei_cl_is_transitioning wrapper to reduce the code
repetition.:

Cc:   # 3.9+
Signed-off-by: Tomas Winkler 
---
 drivers/misc/mei/bus.c|  5 -
 drivers/misc/mei/client.h |  6 ++
 drivers/misc/mei/main.c   | 11 ---
 3 files changed, 14 insertions(+), 8 deletions(-)

diff --git a/drivers/misc/mei/bus.c b/drivers/misc/mei/bus.c
index a150a42..f5dabb3 100644
--- a/drivers/misc/mei/bus.c
+++ b/drivers/misc/mei/bus.c
@@ -295,10 +295,13 @@ int __mei_cl_recv(struct mei_cl *cl, u8 *buf, size_t 
length)
 
if (cl->reading_state != MEI_READ_COMPLETE &&
!waitqueue_active(>rx_wait)) {
+
mutex_unlock(>device_lock);
 
if (wait_event_interruptible(cl->rx_wait,
-   (MEI_READ_COMPLETE == cl->reading_state))) {
+   cl->reading_state == MEI_READ_COMPLETE  ||
+   mei_cl_is_transitioning(cl))) {
+
if (signal_pending(current))
return -EINTR;
return -ERESTARTSYS;
diff --git a/drivers/misc/mei/client.h b/drivers/misc/mei/client.h
index 9eb031e..892cc42 100644
--- a/drivers/misc/mei/client.h
+++ b/drivers/misc/mei/client.h
@@ -90,6 +90,12 @@ static inline bool mei_cl_is_connected(struct mei_cl *cl)
cl->dev->dev_state == MEI_DEV_ENABLED &&
cl->state == MEI_FILE_CONNECTED);
 }
+static inline bool mei_cl_is_transitioning(struct mei_cl *cl)
+{
+   return (MEI_FILE_INITIALIZING == cl->state ||
+   MEI_FILE_DISCONNECTED == cl->state ||
+   MEI_FILE_DISCONNECTING == cl->state);
+}
 
 bool mei_cl_is_other_connecting(struct mei_cl *cl);
 int mei_cl_disconnect(struct mei_cl *cl);
diff --git a/drivers/misc/mei/main.c b/drivers/misc/mei/main.c
index 7404584..b8f8604 100644
--- a/drivers/misc/mei/main.c
+++ b/drivers/misc/mei/main.c
@@ -255,19 +255,16 @@ static ssize_t mei_read(struct file *file, char __user 
*ubuf,
mutex_unlock(>device_lock);
 
if (wait_event_interruptible(cl->rx_wait,
-   (MEI_READ_COMPLETE == cl->reading_state ||
-MEI_FILE_INITIALIZING == cl->state ||
-MEI_FILE_DISCONNECTED == cl->state ||
-MEI_FILE_DISCONNECTING == cl->state))) {
+   MEI_READ_COMPLETE == cl->reading_state ||
+   mei_cl_is_transitioning(cl))) {
+
if (signal_pending(current))
return -EINTR;
return -ERESTARTSYS;
}
 
mutex_lock(>device_lock);
-   if (MEI_FILE_INITIALIZING == cl->state ||
-   MEI_FILE_DISCONNECTED == cl->state ||
-   MEI_FILE_DISCONNECTING == cl->state) {
+   if (mei_cl_is_transitioning(cl)) {
rets = -EBUSY;
goto out;
}
-- 
1.8.3.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[char-misc-next 2/3] mei: bus: stop wait for read during cl state transition

2013-09-02 Thread Tomas Winkler
Bus layer omitted check for client state transition while waiting
for read completion
The client state transition may occur for example as result
of firmware initiated reset

Add mei_cl_is_transitioning wrapper to reduce the code
repetition.:

Cc:  sta...@vger.kernel.org # 3.9+
Signed-off-by: Tomas Winkler tomas.wink...@intel.com
---
 drivers/misc/mei/bus.c|  5 -
 drivers/misc/mei/client.h |  6 ++
 drivers/misc/mei/main.c   | 11 ---
 3 files changed, 14 insertions(+), 8 deletions(-)

diff --git a/drivers/misc/mei/bus.c b/drivers/misc/mei/bus.c
index a150a42..f5dabb3 100644
--- a/drivers/misc/mei/bus.c
+++ b/drivers/misc/mei/bus.c
@@ -295,10 +295,13 @@ int __mei_cl_recv(struct mei_cl *cl, u8 *buf, size_t 
length)
 
if (cl-reading_state != MEI_READ_COMPLETE 
!waitqueue_active(cl-rx_wait)) {
+
mutex_unlock(dev-device_lock);
 
if (wait_event_interruptible(cl-rx_wait,
-   (MEI_READ_COMPLETE == cl-reading_state))) {
+   cl-reading_state == MEI_READ_COMPLETE  ||
+   mei_cl_is_transitioning(cl))) {
+
if (signal_pending(current))
return -EINTR;
return -ERESTARTSYS;
diff --git a/drivers/misc/mei/client.h b/drivers/misc/mei/client.h
index 9eb031e..892cc42 100644
--- a/drivers/misc/mei/client.h
+++ b/drivers/misc/mei/client.h
@@ -90,6 +90,12 @@ static inline bool mei_cl_is_connected(struct mei_cl *cl)
cl-dev-dev_state == MEI_DEV_ENABLED 
cl-state == MEI_FILE_CONNECTED);
 }
+static inline bool mei_cl_is_transitioning(struct mei_cl *cl)
+{
+   return (MEI_FILE_INITIALIZING == cl-state ||
+   MEI_FILE_DISCONNECTED == cl-state ||
+   MEI_FILE_DISCONNECTING == cl-state);
+}
 
 bool mei_cl_is_other_connecting(struct mei_cl *cl);
 int mei_cl_disconnect(struct mei_cl *cl);
diff --git a/drivers/misc/mei/main.c b/drivers/misc/mei/main.c
index 7404584..b8f8604 100644
--- a/drivers/misc/mei/main.c
+++ b/drivers/misc/mei/main.c
@@ -255,19 +255,16 @@ static ssize_t mei_read(struct file *file, char __user 
*ubuf,
mutex_unlock(dev-device_lock);
 
if (wait_event_interruptible(cl-rx_wait,
-   (MEI_READ_COMPLETE == cl-reading_state ||
-MEI_FILE_INITIALIZING == cl-state ||
-MEI_FILE_DISCONNECTED == cl-state ||
-MEI_FILE_DISCONNECTING == cl-state))) {
+   MEI_READ_COMPLETE == cl-reading_state ||
+   mei_cl_is_transitioning(cl))) {
+
if (signal_pending(current))
return -EINTR;
return -ERESTARTSYS;
}
 
mutex_lock(dev-device_lock);
-   if (MEI_FILE_INITIALIZING == cl-state ||
-   MEI_FILE_DISCONNECTED == cl-state ||
-   MEI_FILE_DISCONNECTING == cl-state) {
+   if (mei_cl_is_transitioning(cl)) {
rets = -EBUSY;
goto out;
}
-- 
1.8.3.1

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/