IB/hfi1: Handle missing magic values in config file
authorJan Sokolowski <jan.sokolowski@intel.com>
Fri, 9 Jun 2017 23:00:26 +0000 (16:00 -0700)
committerDoug Ledford <dledford@redhat.com>
Tue, 27 Jun 2017 20:58:13 +0000 (16:58 -0400)
Driver does not check whether proper configuration file exist in EPROM,
and treats empty partition as possible valid configuration, preventing
fallback to default firmware. Change EPROM read function to treat
missing magic number as read error.

Reviewed-by: Jakub Byczkowski <jakub.byczkowski@intel.com>
Signed-off-by: Jan Sokolowski <jan.sokolowski@intel.com>
Signed-off-by: Dennis Dalessandro <dennis.dalessandro@intel.com>
Signed-off-by: Doug Ledford <dledford@redhat.com>
drivers/infiniband/hw/hfi1/eprom.c

index 26da124c88e2094e391e427ed45b233132a76f9d..d46b171079010d2cf7e42dd7557f0abc2bef1348 100644 (file)
@@ -250,7 +250,6 @@ static int read_partition_platform_config(struct hfi1_devdata *dd, void **data,
 {
        void *buffer;
        void *p;
-       u32 length;
        int ret;
 
        buffer = kmalloc(P1_SIZE, GFP_KERNEL);
@@ -265,13 +264,13 @@ static int read_partition_platform_config(struct hfi1_devdata *dd, void **data,
 
        /* scan for image magic that may trail the actual data */
        p = strnstr(buffer, IMAGE_TRAIL_MAGIC, P1_SIZE);
-       if (p)
-               length = p - buffer;
-       else
-               length = P1_SIZE;
+       if (!p) {
+               kfree(buffer);
+               return -ENOENT;
+       }
 
        *data = buffer;
-       *size = length;
+       *size = p - buffer;
        return 0;
 }