Skip to contentSkip to conversation

ata: make ata_port_operations const

PATCH In review Bhumika Goyal 3 participants 6 messages Aug 7, 2017 – Aug 8, 2017 libata

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ata: make ata_port_operations const

Make ata_port_operations structures const as it is only stored in the inherits field of an ata_port_operations structure. Therefore make it const.

---
 drivers/ata/pata_sis.c | 2 +-
 drivers/ata/sata_via.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
drivers/ata/pata_sis.c +1 -1
index 626f989..24614d2 100644
@@ -549,7 +549,7 @@ static unsigned long sis_133_mode_filter(struct ata_device *adev, unsigned long
 	.cable_detect		= sis_133_cable_detect,
 };
 
-static struct ata_port_operations sis_base_ops = {
+static const struct ata_port_operations sis_base_ops = {
 	.inherits		= &ata_bmdma_port_ops,
 	.prereset		= sis_pre_reset,
 };
drivers/ata/sata_via.c +1 -1
index 93b8d78..83ba848 100644
@@ -129,7 +129,7 @@ struct svia_priv {
 	ATA_BMDMA_SHT(DRV_NAME),
 };
 
-static struct ata_port_operations svia_base_ops = {
+static const  struct ata_port_operations svia_base_ops = {
 	.inherits		= &ata_bmdma_port_ops,
 	.sff_tf_load		= svia_tf_load,
 };
Signature · 1 line
1.9.1
#1 lore raw

Hello,

Quoted 5 lines · Bhumika Goyal

Make ata_port_operations structures const as it is only stored in the inherits field of an ata_port_operations structure. Therefore make it const.

How did you test the patch?

Thanks.

Signature · 1 line
tejun
#2 lore raw
Quoted 11 lines · Tejun Heo

Hello,

Quoted 5 lines · Bhumika Goyal

Make ata_port_operations structures const as it is only stored in the inherits field of an ata_port_operations structure. Therefore make it const.

How did you test the patch?

I compiled the .o files and checked the size before and after compilation. After making the structure const, bytes should move from data to text segment of the memory and this is what happened. So, this is how I tested it.

Thanks,
Bhumika

Quoted 4 lines

Thanks.

--
tejun

#3 lore raw

Hello,

Quoted 4 lines · Bhumika Goyal

I compiled the .o files and checked the size before and after compilation. After making the structure const, bytes should move from data to text segment of the memory and this is what happened. So, this is how I tested it.

Ah, I see, so the port_operations is never used directly. I'm not sure whether it'd be a good idea to selectively pick these and makr them const. Let's just leave them be.

Thanks.

Signature · 1 line
tejun
#4 lore raw
Quoted 11 lines · Tejun Heo

Hello,

Quoted 4 lines · Bhumika Goyal

I compiled the .o files and checked the size before and after compilation. After making the structure const, bytes should move from data to text segment of the memory and this is what happened. So, this is how I tested it.

Ah, I see, so the port_operations is never used directly. I'm not sure whether it'd be a good idea to selectively pick these and makr them const. Let's just leave them be.

Why?

Things that are never accessed as other than const should be const no?

Why leave unnecessary exposure for muckery?

#5 lore raw
Quoted 9 lines · Joe Perches
Quoted 8 lines · Tejun Heo

Hello,

Quoted 4 lines · Bhumika Goyal

I compiled the .o files and checked the size before and after compilation. After making the structure const, bytes should move from data to text segment of the memory and this is what happened. So, this is how I tested it.

Quoted 9 lines
Quoted 3 lines

Ah, I see, so the port_operations is never used directly. I'm not sure whether it'd be a good idea to selectively pick these and makr them const. Let's just leave them be.

Why?

Things that are never accessed as other than const should be const no?

I think it would be better to leave them as in most situations the ata_port_operations structures cannot be const as they are only used in the port_ops field of an ata_port_info structure and this field is not const. Having two ata_port_operations const and others non-const will cause code inconsistency.

Thanks,
Bhumika

Quoted 1 line

Why leave unnecessary exposure for muckery?