powerpc/papr_scm: Improve error logging and handling papr_scm_ndctl()
authorVaibhav Jain <vaibhav@linux.ibm.com>
Mon, 15 Jun 2020 12:44:05 +0000 (18:14 +0530)
committerDan Williams <dan.j.williams@intel.com>
Tue, 16 Jun 2020 01:22:44 +0000 (18:22 -0700)
Since papr_scm_ndctl() can be called from outside papr_scm, its
exposed to the possibility of receiving NULL as value of 'cmd_rc'
argument. This patch updates papr_scm_ndctl() to protect against such
possibility by assigning it pointer to a local variable in case cmd_rc
== NULL.

Finally the patch also updates the 'default' add a debug log unknown
'cmd' values.

Signed-off-by: Vaibhav Jain <vaibhav@linux.ibm.com>
Reviewed-by: Ira Weiny <ira.weiny@intel.com>
Cc: "Aneesh Kumar K . V" <aneesh.kumar@linux.ibm.com>
Cc: Dan Williams <dan.j.williams@intel.com>
Cc: Michael Ellerman <mpe@ellerman.id.au>
Cc: Ira Weiny <ira.weiny@intel.com>
Link: https://lore.kernel.org/r/20200615124407.32596-5-vaibhav@linux.ibm.com
Signed-off-by: Dan Williams <dan.j.williams@intel.com>
arch/powerpc/platforms/pseries/papr_scm.c

index 0c09162..692ad3d 100644 (file)
@@ -355,11 +355,16 @@ static int papr_scm_ndctl(struct nvdimm_bus_descriptor *nd_desc,
 {
        struct nd_cmd_get_config_size *get_size_hdr;
        struct papr_scm_priv *p;
+       int rc;
 
        /* Only dimm-specific calls are supported atm */
        if (!nvdimm)
                return -EINVAL;
 
+       /* Use a local variable in case cmd_rc pointer is NULL */
+       if (!cmd_rc)
+               cmd_rc = &rc;
+
        p = nvdimm_provider_data(nvdimm);
 
        switch (cmd) {
@@ -381,6 +386,7 @@ static int papr_scm_ndctl(struct nvdimm_bus_descriptor *nd_desc,
                break;
 
        default:
+               dev_dbg(&p->pdev->dev, "Unknown command = %d\n", cmd);
                return -EINVAL;
        }