OSDN Git Service

greybus: svc: reject invalid state requests
authorViresh Kumar <viresh.kumar@linaro.org>
Thu, 3 Sep 2015 10:12:22 +0000 (15:42 +0530)
committerJohan Hovold <johan@hovoldconsulting.com>
Thu, 3 Sep 2015 12:03:46 +0000 (14:03 +0200)
commit3ccb1600babfda0c71cba376e21f4f95a61080a2
tree4db08bdd2b2bfc2e77ca265300ce4a0c0d306a66
parentf66427adfd407ea08236ab541df192e15671b6cf
greybus: svc: reject invalid state requests

The request sequence for SVC protocol is fixed at least upto SVC_HELLO
request. The first request has to be Protocol Version, followed by
SVC_HELLO. Any other request can follow them, but these two.

Add another field in 'struct gb_svc' that keeps track of current state
of the protocol driver. It tracks only upto SVC_HELLO, as we don't need
to track later ones.

Also add a comment, about the order in which the requests are allowed
and why a race can't happen while accessing 'state'.

This removes the WARN_ON() in gb_svc_hello() as we track state
transition with 'state' field.

This also fixes a crash, when the hotplug request is received before
fully initializing the svc connection. The crash mostly happens while
accessing svc->connection->bundle, which is NULL, but can happen at
other places too, as svc connection isn't fully initialized.

Reported-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
[johan: add 0x-prefix to warning message ]
Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
drivers/staging/greybus/svc.c