diff mbox

dm cache: fix up IS_ERR vs NULL confusion

Message ID 20150128121127.GB21433@debian (mailing list archive)
State Accepted, archived
Delegated to: Mike Snitzer
Headers show

Commit Message

Joe Thornber Jan. 28, 2015, 12:11 p.m. UTC
Here's my take.  You were destroying the metadata object with the
mutex still held, which I'd been trying to avoid.

commit ea87d6105c1b13c13ece0fc8d9add09c78b1aa4c
Author: Joe Thornber <ejt@redhat.com>
Date:   Wed Jan 28 12:07:46 2015 +0000

    dm-cache: fixup evil err ptrs that were ommitted from earlier patch.


--
dm-devel mailing list
dm-devel@redhat.com
https://www.redhat.com/mailman/listinfo/dm-devel
diff mbox

Patch

diff --git a/drivers/md/dm-cache-metadata.c b/drivers/md/dm-cache-metadata.c
index 8876250..b6dc968 100644
--- a/drivers/md/dm-cache-metadata.c
+++ b/drivers/md/dm-cache-metadata.c
@@ -683,7 +683,7 @@  static struct dm_cache_metadata *metadata_open(struct block_device *bdev,
        cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
        if (!cmd) {
                DMERR("could not allocate metadata struct");
-               return NULL;
+               return ERR_PTR(-ENOMEM);
        }
 
        atomic_set(&cmd->ref_count, 1);
@@ -745,7 +745,7 @@  static struct dm_cache_metadata *lookup_or_open(struct block_device *bdev,
                return cmd;
 
        cmd = metadata_open(bdev, data_block_size, may_format_device, policy_hint_size);
-       if (cmd) {
+       if (!IS_ERR(cmd)) {
                mutex_lock(&table_lock);
                cmd2 = lookup(bdev);
                if (cmd2) {
@@ -779,9 +779,9 @@  struct dm_cache_metadata *dm_cache_metadata_open(struct block_device *bdev,
                                                 size_t policy_hint_size)
 {
        struct dm_cache_metadata *cmd = lookup_or_open(bdev, data_block_size, may_format_device, policy_hint_size);
-       if (cmd && !same_params(cmd, data_block_size)) {
+       if (!IS_ERR(cmd) && !same_params(cmd, data_block_size)) {
                dm_cache_metadata_close(cmd);
-               return NULL;
+               return ERR_PTR(-EINVAL);
        }
 
        return cmd;