roth: audio: Add NULL checks for TFA devices
Scott Peterson [Wed, 2 Jan 2013 17:45:26 +0000 (09:45 -0800)]
Add checks for valid TFA device instances before
allowing calibration or config changes.

bug 1211900

Change-Id: Ibb5bd6db9ecc93f1320fc6d61f28dbd7ccc394dd
Signed-off-by: Scott Peterson <speterson@nvidia.com>
Reviewed-on: http://git-master/r/190027
Reviewed-by: Automatic_Commit_Validation_User
Reviewed-by: Vinod Subbarayalu <vsubbarayalu@nvidia.com>
GVS: Gerrit_Virtual_Submit

drivers/misc/tfa9887.c

index 5dff8a0..a890391 100644 (file)
@@ -1170,7 +1170,7 @@ static ssize_t tfa9887_cal_show(struct kobject *kobj,
                struct kobj_attribute *attr, char *buf)
 {
        //printk("!tfa9887_cal_show\n");
-       if(calibration_need) {
+       if (calibration_need) {
                memcpy(buf, calibdata, 16);
                //pr_info("copying data\n");
        }
@@ -1183,6 +1183,11 @@ static ssize_t tfa9887_cal_store(struct kobject *kobj,
        ssize_t ret = count;
        unsigned int value;
        //printk("+tfa9887_cal_store: %p, %d\n", buf, count);
+       if (!tfa9887R || !tfa9887L ||
+               !tfa9887R->deviceInit || !tfa9887L->deviceInit) {
+               ret = -EINVAL;
+               goto fail;
+       }
 
        if (!buf || !count) {
                ret = -EINVAL;
@@ -1242,6 +1247,11 @@ static ssize_t tfa9887_config_store(struct kobject *kobj,
        ssize_t ret = count;
 
        //printk("+tfa9887_config_store: %p, %d\n", buf, count);
+       if (!tfa9887R || !tfa9887L ||
+               !tfa9887R->deviceInit || !tfa9887L->deviceInit) {
+               ret = -EINVAL;
+               goto fail;
+       }
 
        if (!buf || !count) {
                ret = -EINVAL;