Skip to contentSkip to conversation

scsi: remove the stream_status member from scsi_stream_status_header

PATCH In review Christoph Hellwig 3 participants 5 messages May 1, 2025 – May 5, 2025 SCSI

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 scsi: remove the stream_status member from scsi_stream_status_header

Having a variable length array at the end of scsi_stream_status_header only cause problems. Remove it and switch the one place that actually used it to use the struct member directly following in the actual on-disk structure instead.

---
 drivers/scsi/sd.c         | 2 +-
 include/scsi/scsi_proto.h | 1 -
 2 files changed, 1 insertion(+), 2 deletions(-)
drivers/scsi/sd.c +1 -1
index 950d8c9fb884..3f6e87705b62 100644
@@ -3215,7 +3215,7 @@ static bool sd_is_perm_stream(struct scsi_disk *sdkp, unsigned int stream_id)
 		return false;
 	if (get_unaligned_be32(&buf.h.len) < sizeof(struct scsi_stream_status))
 		return false;
-	return buf.h.stream_status[0].perm;
+	return buf.s.perm;
 }
 
 static void sd_read_io_hints(struct scsi_disk *sdkp, unsigned char *buffer)
include/scsi/scsi_proto.h +0 -1
index aeca37816506..bc8f2b2226be 100644
@@ -349,7 +349,6 @@ struct scsi_stream_status_header {
 	__be32 len;	/* length in bytes of stream_status[] array. */
 	u16 reserved;
 	__be16 number_of_open_streams;
-	DECLARE_FLEX_ARRAY(struct scsi_stream_status, stream_status);
 };
 
 static_assert(sizeof(struct scsi_stream_status_header) == 8);
Signature · 1 line
2.47.2
#2 lore raw
In reply to Christoph Hellwig
Quoted 4 lines · Christoph Hellwig

Having a variable length array at the end of scsi_stream_status_header only cause problems. Remove it and switch the one place that actually used it to use the struct member directly following in the actual on-disk structure instead.

"on-disk" is misleading since these data structures should not be stored on the storage medium.

Quoted 18 lines
drivers/scsi/sd.c +1 -1
index 950d8c9fb884..3f6e87705b62 100644
@@ -3215,7 +3215,7 @@ static bool sd_is_perm_stream(struct scsi_disk *sdkp, unsigned int stream_id)
  		return false;
  	if (get_unaligned_be32(&buf.h.len) < sizeof(struct scsi_stream_status))
  		return false;
-	return buf.h.stream_status[0].perm;
+	return buf.s.perm;
  }
 
  static void sd_read_io_hints(struct scsi_disk *sdkp, unsigned char *buffer)
include/scsi/scsi_proto.h +0 -0
index aeca37816506..bc8f2b2226be 100644

include/scsi/scsi_proto.h struct scsi_stream_status_header { · line 354

Quoted 7 lines
include/scsi/scsi_proto.h +0 -1
@@ -349,7 +349,6 @@ struct scsi_stream_status_header {
  	__be32 len;	/* length in bytes of stream_status[] array. */
  	u16 reserved;
  	__be16 number_of_open_streams;
-	DECLARE_FLEX_ARRAY(struct scsi_stream_status, stream_status);
  };
 
  static_assert(sizeof(struct scsi_stream_status_header) == 8);

There is an implicit assumption behind this patch, namely that the compiler does not insert padding bytes between struct scsi_stream_status_header and struct scsi_stream_status. Shouldn't this be made explicit with a BUILD_BUG_ON() expression?

Thanks,

Bart.

#3 lore raw
Quoted 4 lines · Bart Van Assche

There is an implicit assumption behind this patch, namely that the compiler does not insert padding bytes between struct scsi_stream_status_header and struct scsi_stream_status. Shouldn't this be made explicit with a BUILD_BUG_ON() expression?

We make that assumption for all our naturally alignend structures in every on-disk and on the wire structure.

#4 lore raw
In reply to Christoph Hellwig

include/scsi/scsi_proto.h struct scsi_stream_status_header { · line 352

Quoted 10 lines · Christoph Hellwig
include/scsi/scsi_proto.h +0 -1
index aeca37816506..bc8f2b2226be 100644
@@ -349,7 +349,6 @@ struct scsi_stream_status_header {
  	__be32 len;	/* length in bytes of stream_status[] array. */
  	u16 reserved;
  	__be16 number_of_open_streams;
-	DECLARE_FLEX_ARRAY(struct scsi_stream_status, stream_status);
  };

An additional note: the following comment needs to be updated since the member it refers to is removed:

/* length in bytes of stream_status[] array. */

Bart.