Skip to contentSkip to conversation

ata: libata-core: initialize native_sectors in ata_hpa_resize()

PATCH In review Simon Que 2 participants 4 messages Jan 24, 2013 – Jan 28, 2013 libata

lore
Share & tools
lore

Simon Que

author
#0 lore raw

PATCH v3 1/1 ata: libata-core: initialize native_sectors in ata_hpa_resize()

Eliminates a compiler warning about uninitialized variable. "warning: 'native_sectors' may be used uninitialized in this function"

---
 drivers/ata/libata-core.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
drivers/ata/libata-core.c +1 -1
index d2b18ea..b185db1 100644
@@ -1324,7 +1324,7 @@ static int ata_hpa_resize(struct ata_device *dev)
 	int print_info = ehc->i.flags & ATA_EHI_PRINTINFO;
 	bool unlock_hpa = ata_ignore_hpa || dev->flags & ATA_DFLAG_UNLOCK_HPA;
 	u64 sectors = ata_id_n_sectors(dev->id);
-	u64 native_sectors;
+	u64 native_sectors = 0;
 	int rc;
 
 	/* do we need to do it? */
Signature · 1 line
1.7.8.6
#1 lore raw

Hello.

Quoted 13 lines · Simon Que

Eliminates a compiler warning about uninitialized variable. "warning: 'native_sectors' may be used uninitialized in this function"

---
  drivers/ata/libata-core.c |    2 +-
  1 files changed, 1 insertions(+), 1 deletions(-)
drivers/ata/libata-core.c +0 -0
index d2b18ea..b185db1 100644

drivers/ata/libata-core.c static int ata_hpa_resize(struct ata_device *dev) · line 1327

Quoted 5 lines
drivers/ata/libata-core.c +1 -1
@@ -1324,7 +1324,7 @@ static int ata_hpa_resize(struct ata_device *dev)
  	int print_info = ehc->i.flags & ATA_EHI_PRINTINFO;
  	bool unlock_hpa = ata_ignore_hpa || dev->flags & ATA_DFLAG_UNLOCK_HPA;
  	u64 sectors = ata_id_n_sectors(dev->id);
-	u64 native_sectors;
+	u64 native_sectors = 0;

Isn't it wiser to set it to 'sectors'? And frankly speaking I don't see
how this variable may indeed be used unitialized. What version of gcc are you using?

MBR, Sergei

author
#2 lore raw

I'm using a ChromeOS / ChromiumOS gcc.

Technically it won't be used uninitialized since there's a check for the return value. But this isn't always obvious to the compiler -- it'd have to be smart enough to look at ata_read_native_max_address() to see that if '*max_sectors' is not set, then there is a nonzero return value, which would cause ata_hpa_resize() to return early.

This patch is really meant to satisfy the compiler, rather than to catch some corner case where 'native_sectors' gets used uninitialized.
Setting it to 0 makes more sense because its "true initialization" is
in a later call.

Quoted 34 lines · Sergei Shtylyov

Hello.

Quoted 15 lines · Simon Que

Eliminates a compiler warning about uninitialized variable. "warning: 'native_sectors' may be used uninitialized in this function"

---
  drivers/ata/libata-core.c |    2 +-
  1 files changed, 1 insertions(+), 1 deletions(-)
drivers/ata/libata-core.c +0 -0
index d2b18ea..b185db1 100644

drivers/ata/libata-core.c static int ata_hpa_resize(struct ata_device *dev) · line 1328

Quoted 6 lines
drivers/ata/libata-core.c +1 -1
@@ -1324,7 +1324,7 @@ static int ata_hpa_resize(struct ata_device *dev)
        int print_info = ehc->i.flags & ATA_EHI_PRINTINFO;
        bool unlock_hpa = ata_ignore_hpa || dev->flags &
 ATA_DFLAG_UNLOCK_HPA;
        u64 sectors = ata_id_n_sectors(dev->id);
-       u64 native_sectors;
+       u64 native_sectors = 0;

Isn't it wiser to set it to 'sectors'? And frankly speaking I don't see
how this variable may indeed be used unitialized. What version of gcc are you using?

MBR, Sergei

author
#3 lore raw

More specifically... I have gcc 4.7.1.

Quoted 48 lines · Simon Que

I'm using a ChromeOS / ChromiumOS gcc.

Technically it won't be used uninitialized since there's a check for the return value. But this isn't always obvious to the compiler -- it'd have to be smart enough to look at ata_read_native_max_address() to see that if '*max_sectors' is not set, then there is a nonzero return value, which would cause ata_hpa_resize() to return early.

This patch is really meant to satisfy the compiler, rather than to catch some corner case where 'native_sectors' gets used uninitialized.
Setting it to 0 makes more sense because its "true initialization" is
in a later call.

Quoted 34 lines · Sergei Shtylyov

Hello.

Quoted 15 lines · Simon Que

Eliminates a compiler warning about uninitialized variable. "warning: 'native_sectors' may be used uninitialized in this function"

---
  drivers/ata/libata-core.c |    2 +-
  1 files changed, 1 insertions(+), 1 deletions(-)
drivers/ata/libata-core.c +0 -0
index d2b18ea..b185db1 100644

drivers/ata/libata-core.c static int ata_hpa_resize(struct ata_device *dev) · line 1328

Quoted 6 lines
drivers/ata/libata-core.c +1 -1
@@ -1324,7 +1324,7 @@ static int ata_hpa_resize(struct ata_device *dev)
        int print_info = ehc->i.flags & ATA_EHI_PRINTINFO;
        bool unlock_hpa = ata_ignore_hpa || dev->flags &
 ATA_DFLAG_UNLOCK_HPA;
        u64 sectors = ata_id_n_sectors(dev->id);
-       u64 native_sectors;
+       u64 native_sectors = 0;

Isn't it wiser to set it to 'sectors'? And frankly speaking I don't see
how this variable may indeed be used unitialized. What version of gcc are you using?

MBR, Sergei