On Fri, Dec 17, 2021 at 6:25 PM Vishal Verma <[email protected]> wrote: > > Static analysis points out that the function above has a check for > 'if (!bridge)', implying that bridge maybe NULL, but it is dereferenced > before the check, which could result in a NULL dereference. > > Fix this by moving any accesses to the bridge structure after the NULL > check. > > Cc: Dan Williams <[email protected]> > Signed-off-by: Vishal Verma <[email protected]>
LGTM Reviewed-by: Dan Williams <[email protected]> > --- > cxl/lib/libcxl.c | 7 +++++-- > 1 file changed, 5 insertions(+), 2 deletions(-) > > diff --git a/cxl/lib/libcxl.c b/cxl/lib/libcxl.c > index f0664be..3390eb9 100644 > --- a/cxl/lib/libcxl.c > +++ b/cxl/lib/libcxl.c > @@ -420,12 +420,15 @@ CXL_EXPORT int cxl_memdev_nvdimm_bridge_active(struct > cxl_memdev *memdev) > { > struct cxl_ctx *ctx = cxl_memdev_get_ctx(memdev); > struct cxl_nvdimm_bridge *bridge = memdev->bridge; > - char *path = bridge->dev_buf; > - int len = bridge->buf_len; > + char *path; > + int len; > > if (!bridge) > return 0; > > + path = bridge->dev_buf; > + len = bridge->buf_len; > + > if (snprintf(path, len, "%s/driver", bridge->dev_path) >= len) { > err(ctx, "%s: nvdimm bridge buffer too small!\n", > cxl_memdev_get_devname(memdev)); > > base-commit: 8f4e42c0c526e85b045fd0329df7cb904f511c98 > prerequisite-patch-id: acc28fefb6680c477864561902d1560c300fa4a9 > prerequisite-patch-id: c749c331eb4a521c8f0b0820e3dda7ac521926d0 > prerequisite-patch-id: 9fc7ac4fe29689b9c4de00924a9e455cd9b58d53 > prerequisite-patch-id: e019f2c873ac1b93d80b9c260336e5d3f46b0925 > prerequisite-patch-id: b69ecc9d68ce5e7c79b62cea257663519f630da2 > prerequisite-patch-id: 928a32f4c1ff844df809ccf1aba8315cac723d93 > prerequisite-patch-id: ae29f23cedf529da1fe8e39f8cde1df827d75fa1 > prerequisite-patch-id: f3d8fc575f5afed65be8a7b486962e8384eabc1a > prerequisite-patch-id: 74859f43302dcc442dfb1e29f6babad75d229bf1 > prerequisite-patch-id: 696c2d5caf0bd4eac645035f72a7077efbf3e6cd > prerequisite-patch-id: e3ef7893a1df9ecc6b76dee78f2b27cc933ad891 git-send-email adds this by default now?
