Skip to contentSkip to conversation

mtd: return -ENOMEM when kmalloc failed

PATCH Applied Yang Li 2 participants 2 messages Apr 26, 2021 – May 10, 2021 Memory technology devices (MTD)

lore
Share & tools
lore

Yang Li

author
#0 lore raw

PATCH 1/1 mtd: return -ENOMEM when kmalloc failed

The driver is using -1 instead of the -ENOMEM defined macro to specify that a buffer allocation failed. Using the correct error code is more intuitive

Smatch tool warning:
drivers/mtd/inftlmount.c:333 check_free_sectors() warn: returning -1 instead of -ENOMEM is sloppy
drivers/mtd/nftlmount.c:272 check_free_sectors() warn: returning -1 instead of -ENOMEM is sloppy

No functional change, just more standardized.

---
 drivers/mtd/inftlmount.c | 2 +-
 drivers/mtd/nftlmount.c  | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
drivers/mtd/inftlmount.c +1 -1
index af16d34..39d0241 100644
@@ -330,7 +330,7 @@ static int check_free_sectors(struct INFTLrecord *inftl, unsigned int address,
 
 	buf = kmalloc(SECTORSIZE + mtd->oobsize, GFP_KERNEL);
 	if (!buf)
-		return -1;
+		return -ENOMEM;
 
 	ret = -1;
 	for (i = 0; i < len; i += SECTORSIZE) {
drivers/mtd/nftlmount.c +1 -1
index 444a77b..fd331bc 100644
@@ -269,7 +269,7 @@ static int check_free_sectors(struct NFTLrecord *nftl, unsigned int address, int
 
 	buf = kmalloc(SECTORSIZE + mtd->oobsize, GFP_KERNEL);
 	if (!buf)
-		return -1;
+		return -ENOMEM;
 
 	ret = -1;
 	for (i = 0; i < len; i += SECTORSIZE) {
Signature · 1 line
1.8.3.1
maintainer Applied
#1 lore raw
Quoted 10 lines · Yang Li

The driver is using -1 instead of the -ENOMEM defined macro to specify that a buffer allocation failed. Using the correct error code is more intuitive

Smatch tool warning:
drivers/mtd/inftlmount.c:333 check_free_sectors() warn: returning -1 instead of -ENOMEM is sloppy
drivers/mtd/nftlmount.c:272 check_free_sectors() warn: returning -1 instead of -ENOMEM is sloppy

Quoted 4 lines

No functional change, just more standardized.

Applied to https://git.kernel.org/pub/scm/linux/kernel/git/mtd/linux.git mtd/next, thanks.

Miquel

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/