[PATCH 2/2] lightNVM: register bm in nvm_create_target if dev->bm is NULL

From: Dongsheng Yang
Date: Thu Sep 03 2015 - 19:10:13 EST


When we create target, we need to make sure dev->bm is not NULL.
If it's NULL try to register bm again. If we still fail to find
a proper bm for this dev, return error rather than continue to
provide a NULL pointer dereference problem later.

Signed-off-by: Dongsheng Yang <yangds.fnst@xxxxxxxxxxxxxx>
---
drivers/lightnvm/core.c | 20 ++++++++++++++++++++
1 file changed, 20 insertions(+)

diff --git a/drivers/lightnvm/core.c b/drivers/lightnvm/core.c
index 5e4c2b8..9c75ea4 100644
--- a/drivers/lightnvm/core.c
+++ b/drivers/lightnvm/core.c
@@ -293,10 +293,30 @@ static int nvm_create_target(struct nvm_dev *dev, char *ttname, char *tname,
int lun_begin, int lun_end)
{
struct request_queue *tqueue;
+ struct nvm_bm_type *bt;
struct gendisk *tdisk;
struct nvm_tgt_type *tt;
struct nvm_target *t;
void *targetdata;
+ int ret = 0;
+
+ if (!dev->bm) {
+ /* register with device with a supported BM */
+ list_for_each_entry(bt, &nvm_bms, list) {
+ ret = bt->register_bm(dev);
+ if (ret < 0)
+ return ret; /* initialization failed */
+ if (ret > 0) {
+ dev->bm = bt;
+ break; /* successfully initialized */
+ }
+ }
+
+ if (!ret) {
+ pr_info("nvm: no compatible bm was found.\n");
+ return -ENODEV;
+ }
+ }

tt = nvm_find_target_type(ttname);
if (!tt) {
--
1.8.4.2


--------------000500080007030902000901
Content-Type: text/x-patch;
name="0001-lightNVM-fix-a-compatibility-problem-in-compiling.patch"
Content-Transfer-Encoding: 8bit
Content-Disposition: attachment;
filename="0001-lightNVM-fix-a-compatibility-problem-in-compiling.patch"