From 2975617421f843cac23eeb573a31d541f2aef9cf Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Wed, 22 Jul 2015 18:21:04 -0700 Subject: [PATCH] greybus: connection: prevent oops for protocol_id sysfs file If we don't have a protocol assigned to a connection, don't oops when trying to read the "protocol_id" sysfs file. Fixes Jira SW-968. Reported-by: Alexandre Bailon Signed-off-by: Greg Kroah-Hartman Reviewed-by: Viresh Kumar --- drivers/staging/greybus/connection.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/drivers/staging/greybus/connection.c b/drivers/staging/greybus/connection.c index 4663397..cac04dd 100644 --- a/drivers/staging/greybus/connection.c +++ b/drivers/staging/greybus/connection.c @@ -80,7 +80,10 @@ protocol_id_show(struct device *dev, struct device_attribute *attr, char *buf) { struct gb_connection *connection = to_gb_connection(dev); - return sprintf(buf, "%d\n", connection->protocol->id); + if (connection->protocol) + return sprintf(buf, "%d\n", connection->protocol->id); + else + return -EINVAL; } static DEVICE_ATTR_RO(protocol_id); -- 2.7.4