Skip to content

Commit 9baabde

Browse files
committed
hwmon: (dimmtemp) Fix bitmap handling
Building arm:allmodconfig may fail with the following error. In function 'fortify_memcpy_chk', inlined from 'bitmap_copy' at include/linux/bitmap.h:261:2, inlined from 'bitmap_copy_clear_tail' at include/linux/bitmap.h:270:2, inlined from 'bitmap_from_u64' at include/linux/bitmap.h:622:2, inlined from 'check_populated_dimms' at drivers/hwmon/peci/dimmtemp.c:284:2: include/linux/fortify-string.h:344:25: error: call to '__write_overflow_field' declared with attribute warning: detected write beyond size of field (1st parameter) The problematic code is bitmap_from_u64(priv->dimm_mask, dimm_mask); dimm_mask is declared as u64, but the bitmap in priv->dimm_mask is only 24 bit wide. On 32-bit systems, this results in writes over the end of the bitmap. Fix the problem by using u32 instead of u64 for dimm_mask. This is currently sufficient, and a compile time check to ensure that the number of dimms does not exceed the bit map size is already in place. Fixes: 73bc1b8 ("hwmon: peci: Add dimmtemp driver") Cc: Iwona Winiarska <iwona.winiarska@intel.com> Reviewed-by: Iwona Winiarska <iwona.winiarska@intel.com> Signed-off-by: Guenter Roeck <linux@roeck-us.net>
1 parent 45988d9 commit 9baabde

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

drivers/hwmon/peci/dimmtemp.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ static int check_populated_dimms(struct peci_dimmtemp *priv)
220220
int chan_rank_max = priv->gen_info->chan_rank_max;
221221
int dimm_idx_max = priv->gen_info->dimm_idx_max;
222222
u32 chan_rank_empty = 0;
223-
u64 dimm_mask = 0;
223+
u32 dimm_mask = 0;
224224
int chan_rank, dimm_idx, ret;
225225
u32 pcs;
226226

@@ -279,9 +279,9 @@ static int check_populated_dimms(struct peci_dimmtemp *priv)
279279
return -EAGAIN;
280280
}
281281

282-
dev_dbg(priv->dev, "Scanned populated DIMMs: %#llx\n", dimm_mask);
282+
dev_dbg(priv->dev, "Scanned populated DIMMs: %#x\n", dimm_mask);
283283

284-
bitmap_from_u64(priv->dimm_mask, dimm_mask);
284+
bitmap_from_arr32(priv->dimm_mask, &dimm_mask, DIMM_NUMS_MAX);
285285

286286
return 0;
287287
}

0 commit comments

Comments
 (0)