lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:	Tue, 31 Mar 2015 16:27:09 +0300
From:	Boaz Harrosh <boaz@...xistor.com>
To:	Christoph Hellwig <hch@....de>
CC:	linux-nvdimm@...1.01.org, linux-fsdevel@...r.kernel.org,
	linux-kernel@...r.kernel.org, x86@...nel.org,
	ross.zwisler@...ux.intel.com, axboe@...nel.dk
Subject: [PATCH 4/6] SQUSHME: pmem: Micro cleaning


Some error checks had unlikely some did not. Put unlikely
on all error handling paths.
(I like unlikely for error paths specially for readability)

Also use bio_data_dir() to extract away the READA flag

Signed-off-by: Boaz Harrosh <boaz@...xistor.com>
---
 drivers/block/pmem.c | 16 +++++++---------
 1 file changed, 7 insertions(+), 9 deletions(-)

diff --git a/drivers/block/pmem.c b/drivers/block/pmem.c
index 6a45fd5..209a410 100644
--- a/drivers/block/pmem.c
+++ b/drivers/block/pmem.c
@@ -76,7 +76,7 @@ static void pmem_make_request(struct request_queue *q, struct bio *bio)
 	struct bvec_iter iter;
 	int err = 0;
 
-	if (bio_end_sector(bio) > get_capacity(bdev->bd_disk)) {
+	if (unlikely(bio_end_sector(bio) > get_capacity(bdev->bd_disk))) {
 		err = -EIO;
 		goto out;
 	}
@@ -86,9 +86,7 @@ static void pmem_make_request(struct request_queue *q, struct bio *bio)
 		goto out;
 	}
 
-	rw = bio_rw(bio);
-	if (rw == READA)
-		rw = READ;
+	rw = bio_data_dir(bio);
 
 	sector = bio->bi_iter.bi_sector;
 	bio_for_each_segment(bvec, bio, iter) {
@@ -124,7 +122,7 @@ static long pmem_direct_access(struct block_device *bdev, sector_t sector,
 	struct pmem_device *pmem = bdev->bd_disk->private_data;
 	size_t offset = sector << 9;
 
-	if (!pmem)
+	if (unlikely(!pmem))
 		return -ENODEV;
 
 	*kaddr = pmem->virt_addr + offset;
@@ -149,7 +147,7 @@ static int pmem_mapmem(struct pmem_device *pmem)
 
 	res_mem = request_mem_region_exclusive(pmem->phys_addr, pmem->size,
 					       "pmem");
-	if (!res_mem) {
+	if (unlikely(!res_mem)) {
 		pr_warn("pmem: request_mem_region_exclusive phys=0x%llx size=0x%zx failed\n",
 			   pmem->phys_addr, pmem->size);
 		return -EINVAL;
@@ -192,7 +190,7 @@ static int pmem_probe(struct platform_device *pdev)
 		return -ENXIO;
 
 	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
-	if (!res)
+	if (unlikely(!res))
 		return -ENXIO;
 
 	pmem = kzalloc(sizeof(*pmem), GFP_KERNEL);
@@ -273,11 +271,11 @@ static int __init pmem_init(void)
 	int error;
 
 	pmem_major = register_blkdev(0, "pmem");
-	if (pmem_major < 0)
+	if (unlikely(pmem_major < 0))
 		return pmem_major;
 
 	error = platform_driver_register(&pmem_driver);
-	if (error)
+	if (unlikely(error))
 		unregister_blkdev(pmem_major, "pmem");
 	return error;
 }
-- 
1.9.3

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists