Explorar el Código

add the invalid parameter cheching.

Andyli hace 1 mes
padre
commit
3def222170
Se han modificado 1 ficheros con 10 adiciones y 1 borrados
  1. 10 1
      gsensor.c

+ 10 - 1
gsensor.c

@@ -296,8 +296,17 @@ static ssize_t enable_store(struct kobject *kobj, struct kobj_attribute *attr,
         return -ENODEV;
 
     ret = kstrtoul(buf, 0, &val);
-    if (ret)
+    if (ret) {
         return ret;
+    }
+
+    if (val != 0 && val != 1) {
+        dev_err(
+            data->client ? &data->client->dev : NULL,
+            "Invalid value: %lu. Only 0 (disable) or 1 (enable) are accepted\n",
+            val);
+        return -EINVAL;
+    }
 
     mutex_lock(&data->lock);