extcon: palmas: Fix NULL pointer error
[firefly-linux-kernel-4.4.55.git] / ipc / util.c
index 537a41c7f6339190fead16543da6e13448a44019..be4230020a1f718c31b02012554600c710b928b9 100644 (file)
@@ -555,7 +555,7 @@ void ipc64_perm_to_ipc_perm(struct ipc64_perm *in, struct ipc_perm *out)
  * Call inside the RCU critical section.
  * The ipc object is *not* locked on exit.
  */
-struct kern_ipc_perm *ipc_obtain_object(struct ipc_ids *ids, int id)
+struct kern_ipc_perm *ipc_obtain_object_idr(struct ipc_ids *ids, int id)
 {
        struct kern_ipc_perm *out;
        int lid = ipcid_to_idx(id);
@@ -581,21 +581,24 @@ struct kern_ipc_perm *ipc_lock(struct ipc_ids *ids, int id)
        struct kern_ipc_perm *out;
 
        rcu_read_lock();
-       out = ipc_obtain_object(ids, id);
+       out = ipc_obtain_object_idr(ids, id);
        if (IS_ERR(out))
-               goto err1;
+               goto err;
 
        spin_lock(&out->lock);
 
-       /* ipc_rmid() may have already freed the ID while ipc_lock
-        * was spinning: here verify that the structure is still valid
+       /*
+        * ipc_rmid() may have already freed the ID while ipc_lock()
+        * was spinning: here verify that the structure is still valid.
+        * Upon races with RMID, return -EIDRM, thus indicating that
+        * the ID points to a removed identifier.
         */
        if (ipc_valid_object(out))
                return out;
 
        spin_unlock(&out->lock);
-       out = ERR_PTR(-EINVAL);
-err1:
+       out = ERR_PTR(-EIDRM);
+err:
        rcu_read_unlock();
        return out;
 }
@@ -605,7 +608,7 @@ err1:
  * @ids: ipc identifier set
  * @id: ipc id to look for
  *
- * Similar to ipc_obtain_object() but also checks
+ * Similar to ipc_obtain_object_idr() but also checks
  * the ipc object reference counter.
  *
  * Call inside the RCU critical section.
@@ -613,13 +616,13 @@ err1:
  */
 struct kern_ipc_perm *ipc_obtain_object_check(struct ipc_ids *ids, int id)
 {
-       struct kern_ipc_perm *out = ipc_obtain_object(ids, id);
+       struct kern_ipc_perm *out = ipc_obtain_object_idr(ids, id);
 
        if (IS_ERR(out))
                goto out;
 
        if (ipc_checkid(out, id))
-               return ERR_PTR(-EIDRM);
+               return ERR_PTR(-EINVAL);
 out:
        return out;
 }