Fix Undefined behavior from signed bit shifts (#871)

* libhsakmt: fix UB due to signed integer literal in 1 << 31

Bit shift operations on signed numbers should not shift into or beyond
the signed bit as this results in Undefined Behaviour.

Signed-off-by: Sunday Clement <Sunday.Clement@amd.com>

* libhsakmt: Fix UB due to signed integer literal in 1 << x

Bit Shifting an unsigned integer is undefined behavior.

BUG: SWDEV-532853

Signed-off-by: Sunday Clement <Sunday.Clement@amd.com>

* rocr: Fix UB in various places due signed integer in bit shift

Bit shifting signed integers into or beyond the sign bit is undefined.

Signed-off-by: Sunday Clement <Sunday.Clement@amd.com>

* rocr: Change signed integer literals to unsigned

Changing the signed integers in the macro expressions throughout the file
to avoid overflow.

Signed-off-by: Sunday Clement <Sunday.Clement@amd.com>

---------

Signed-off-by: Sunday Clement <Sunday.Clement@amd.com>
Co-authored-by: Flora Cui <flora.cui@amd.com>
Bu işleme şunda yer alıyor:
Sunday Clement
2025-09-18 09:09:30 -04:00
işlemeyi yapan: GitHub
ebeveyn 5c1eebab84
işleme 7c8e575f5d
5 değiştirilmiş dosya ile 87 ekleme ve 87 silme
+1 -1
Dosyayı Görüntüle
@@ -663,7 +663,7 @@ HSAKMT_STATUS HSAKMTAPI hsaKmtCreateQueueExt(HSAuint32 NodeId,
/* cu_mask_count counts bits. It must be multiple of 32 */
q->cu_mask_count = ALIGN_UP_32(cu_num, 32);
for (i = 0; i < cu_num; i++)
q->cu_mask[i/32] |= (1 << (i % 32));
q->cu_mask[i/32] |= (1U << (i % 32));
}
struct kfd_ioctl_create_queue_args args = {0};
+1 -1
Dosyayı Görüntüle
@@ -33,7 +33,7 @@ struct rbtree_key_s {
unsigned long addr;
unsigned long size;
};
#define BIT(x) (1<<(x))
#define BIT(x) (1U<<(x))
#define LKP_ALL (BIT(ADDR_BIT) | BIT(SIZE_BIT))
#define LKP_ADDR (BIT(ADDR_BIT))
#define LKP_ADDR_SIZE (BIT(ADDR_BIT) | BIT(SIZE_BIT))
+2 -2
Dosyayı Görüntüle
@@ -469,7 +469,7 @@ static void cpumap_to_cpu_ci(char *shared_cpu_map,
struct proc_cpuinfo *cpuinfo,
HsaCacheProperties *this_cache)
{
int num_hexs, bit;
uint32_t num_hexs, bit;
uint32_t proc, apicid, mask;
char *ch_ptr;
@@ -482,7 +482,7 @@ static void cpumap_to_cpu_ci(char *shared_cpu_map,
while (num_hexs-- > 0) {
mask = strtol(ch_ptr, NULL, 16); /* each X */
for (bit = 0; bit < 32; bit++) {
if (!((1 << bit) & mask))
if (!((1U << bit) & mask))
continue;
proc = num_hexs * 32 + bit;
apicid = cpuinfo[proc].apicid;