Skip to content

Commit 468c9d9

Browse files
Russ Weightyilunxu1984
authored andcommitted
fpga: m10bmc-sec: Fix possible memory leak of flash_buf
There is an error check following the allocation of flash_buf that returns without freeing flash_buf. It makes more sense to do the error check before the allocation and the reordering eliminates the memory leak. Reported-by: kernel test robot <lkp@intel.com> Reported-by: Dan Carpenter <dan.carpenter@oracle.com> Fixes: 154afa5 ("fpga: m10bmc-sec: expose max10 flash update count") Signed-off-by: Russ Weight <russell.h.weight@intel.com> Reviewed-by: Tom Rix <trix@redhat.com> Acked-by: Xu Yilun <yilun.xu@intel.com> Cc: <stable@vger.kernel.org> Link: https://lore.kernel.org/r/20220916235205.106873-1-russell.h.weight@intel.com Signed-off-by: Xu Yilun <yilun.xu@intel.com>
1 parent 568035b commit 468c9d9

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

drivers/fpga/intel-m10-bmc-sec-update.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -148,10 +148,6 @@ static ssize_t flash_count_show(struct device *dev,
148148
stride = regmap_get_reg_stride(sec->m10bmc->regmap);
149149
num_bits = FLASH_COUNT_SIZE * 8;
150150

151-
flash_buf = kmalloc(FLASH_COUNT_SIZE, GFP_KERNEL);
152-
if (!flash_buf)
153-
return -ENOMEM;
154-
155151
if (FLASH_COUNT_SIZE % stride) {
156152
dev_err(sec->dev,
157153
"FLASH_COUNT_SIZE (0x%x) not aligned to stride (0x%x)\n",
@@ -160,6 +156,10 @@ static ssize_t flash_count_show(struct device *dev,
160156
return -EINVAL;
161157
}
162158

159+
flash_buf = kmalloc(FLASH_COUNT_SIZE, GFP_KERNEL);
160+
if (!flash_buf)
161+
return -ENOMEM;
162+
163163
ret = regmap_bulk_read(sec->m10bmc->regmap, STAGING_FLASH_COUNT,
164164
flash_buf, FLASH_COUNT_SIZE / stride);
165165
if (ret) {

0 commit comments

Comments
 (0)