Skip to contentSkip to conversation

drm/amdgpu: Use flexible array member

PATCH In review Lijo Lazar 3 participants 3 messages Apr 8, 2022

Subsystems (2)
lore
Share & tools
lore

Lijo Lazar

author
#0 lore raw

PATCH v2 1/1 drm/amdgpu: Use flexible array member

Use flexible array member in ip discovery struct as recommended[1].

[1] https://www.kernel.org/doc/html/latest/process/deprecated.html#zero-length-and-one-element-arrays

---
v2 : Use struct_size (Christian)

 drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c | 2 +-
 drivers/gpu/drm/amd/include/discovery.h       | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c +1 -1
index 5a182288391b..766006a075ec 100644
@@ -430,7 +430,7 @@ static void amdgpu_discovery_read_harvest_bit_per_ip(struct amdgpu_device *adev,
                                 }
                         }
 next_ip:
-			ip_offset += sizeof(*ip) + 4 * (ip->num_base_address - 1);
+			ip_offset += struct_size(ip, base_address, ip->num_base_address);
 		}
 	}
 }
drivers/gpu/drm/amd/include/discovery.h +1 -1
index a486769b66c6..b25026c3ec96 100644
@@ -93,7 +93,7 @@ typedef struct ip
 	uint8_t harvest : 4;      /* Harvest */
 	uint8_t reserved : 4;     /* Placeholder field */
 #endif
-	uint32_t base_address[1]; /* variable number of Addresses */
+	uint32_t base_address[]; /* variable number of Addresses */
 } ip;
 
 typedef struct die_header
Signature · 1 line
2.25.1
Reviewed-by on v2 1/1
#1 lore raw

Am 08.04.22 um 12:07 schrieb Lijo Lazar:

Quoted 5 lines

Use flexible array member in ip discovery struct as recommended[1].

[1] https://www.kernel.org/doc/html/latest/process/deprecated.html#zero-length-and-one-element-arrays

Quoted 33 lines

---
v2 : Use struct_size (Christian)

  drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c | 2 +-
  drivers/gpu/drm/amd/include/discovery.h       | 2 +-
  2 files changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c +1 -1
index 5a182288391b..766006a075ec 100644
@@ -430,7 +430,7 @@ static void amdgpu_discovery_read_harvest_bit_per_ip(struct amdgpu_device *adev,
                                  }
                          }
  next_ip:
-			ip_offset += sizeof(*ip) + 4 * (ip->num_base_address - 1);
+			ip_offset += struct_size(ip, base_address, ip->num_base_address);
  		}
  	}
  }
drivers/gpu/drm/amd/include/discovery.h +1 -1
index a486769b66c6..b25026c3ec96 100644
@@ -93,7 +93,7 @@ typedef struct ip
  	uint8_t harvest : 4;      /* Harvest */
  	uint8_t reserved : 4;     /* Placeholder field */
  #endif
-	uint32_t base_address[1]; /* variable number of Addresses */
+	uint32_t base_address[]; /* variable number of Addresses */
  } ip;
 
  typedef struct die_header
Reviewed-by on v2 1/1
#2 lore raw
In reply to Lijo Lazar

[AMD Official Use Only]

Regards,
Hawking
-----Original Message-----
From: Lazar, Lijo <[email protected]>
Sent: Friday, April 8, 2022 18:07
To: [email protected]
Cc: Zhang, Hawking <[email protected]>; Deucher, Alexander <[email protected]>
Subject: [PATCH v2] drm/amdgpu: Use flexible array member

Use flexible array member in ip discovery struct as recommended[1].

[1] https://www.kernel.org/doc/html/latest/process/deprecated.html#zero-length-and-one-element-arrays

---
v2 : Use struct_size (Christian)

 drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c | 2 +-
 drivers/gpu/drm/amd/include/discovery.h       | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c +1 -1
index 5a182288391b..766006a075ec 100644
@@ -430,7 +430,7 @@ static void amdgpu_discovery_read_harvest_bit_per_ip(struct amdgpu_device *adev,
                                 }
                         }
 next_ip:
-                       ip_offset += sizeof(*ip) + 4 * (ip->num_base_address - 1);
+                       ip_offset += struct_size(ip, base_address, ip->num_base_address);
                }
        }
 }
drivers/gpu/drm/amd/include/discovery.h +1 -1
index a486769b66c6..b25026c3ec96 100644
@@ -93,7 +93,7 @@ typedef struct ip
        uint8_t harvest : 4;      /* Harvest */
        uint8_t reserved : 4;     /* Placeholder field */
 #endif
-       uint32_t base_address[1]; /* variable number of Addresses */
+       uint32_t base_address[]; /* variable number of Addresses */
 } ip;
 
 typedef struct die_header

--
2.25.1