[COMMON] usb: typec: check invalid accessory id
authorKisang Lee <kisang80.lee@samsung.com>
Mon, 25 Jun 2018 05:36:04 +0000 (14:36 +0900)
committerTaekki Kim <taekki.kim@samsung.com>
Mon, 25 Jun 2018 13:40:28 +0000 (22:40 +0900)
Change-Id: I243f47c1782cf59f0be9b2caf754d5bf4ba05a19
Signed-off-by: Kisang Lee <kisang80.lee@samsung.com>
drivers/usb/typec/typec.c

index 24e355ba109d3fc36d8bccf68a75068c295d1fc3..393c79e191d97d37bb4139313868b0cd3b14bff6 100644 (file)
@@ -432,7 +432,14 @@ static ssize_t accessory_mode_show(struct device *dev,
                                   struct device_attribute *attr,
                                   char *buf)
 {
-       struct typec_partner *p = to_typec_partner(dev);
+       struct typec_partner *p;
+
+       p = to_typec_partner(dev);
+
+       if (p->accessory > TYPEC_MAX_ACCESSORY) {
+               pr_err("%s Invalid accessory number...", __func__);
+               return sprintf(buf, "%s\n", typec_accessory_modes[0]);
+       }
 
        return sprintf(buf, "%s\n", typec_accessory_modes[p->accessory]);
 }