[PATCH v4 0/1] libnvdimm: fix memory leaks in of_pmem.c

2020-09-01 Thread Zhen Lei
v3 --> v4 1. Merge patch 1 and 2 into one: https://lkml.org/lkml/2020/8/19/1464 Patch 1 https://lkml.org/lkml/2020/8/19/1468 Patch 2 2. The part from patch 1 was reviewed by Oliver O'Halloran Zhen Lei (1): libnvdimm: fix memory leaks in of_pmem.c drivers/nvd

[PATCH v4 1/1] libnvdimm: fix memory leaks in of_pmem.c

2020-09-01 Thread Zhen Lei
xes: 49bddc73d15c ("libnvdimm/of_pmem: Provide a unique name for bus provider") Signed-off-by: Zhen Lei Reviewed-by: Oliver O'Halloran --- drivers/nvdimm/of_pmem.c | 7 +++ 1 file changed, 7 insertions(+) diff --git a/drivers/nvdimm/of_pmem.c b/drivers/nvdimm/of_pmem.c index 10

[PATCH 0/3] bugfix and optimize for drivers/nvdimm

2020-08-17 Thread Zhen Lei
I found a memleak when I learned the drivers/nvdimm code today. And I also added a sanity check for priv->bus_desc.provider_name, because strdup() maybe failed. Patch 3 is a trivial source code optimization. Zhen Lei (3): libnvdimm: fix memleak in of_pmem.c libnvdimm: add sanity ch

[PATCH 2/3] libnvdimm: add sanity check for provider_name in of_pmem_region_probe()

2020-08-17 Thread Zhen Lei
kstrdup() may return NULL because of no memory, check it. Signed-off-by: Zhen Lei --- drivers/nvdimm/of_pmem.c | 5 + 1 file changed, 5 insertions(+) diff --git a/drivers/nvdimm/of_pmem.c b/drivers/nvdimm/of_pmem.c index 1292ffca7b2ecc0..13c4c274ca6ea88 100644 --- a/drivers/nvdimm

[PATCH 1/3] libnvdimm: fix memleak in of_pmem.c

2020-08-17 Thread Zhen Lei
The memory priv->bus_desc.provider_name allocated by kstrdup() should be freed. Signed-off-by: Zhen Lei --- drivers/nvdimm/of_pmem.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/nvdimm/of_pmem.c b/drivers/nvdimm/of_pmem.c index 10dbdcdfb9ce913..1292ffca7b2ecc0 100

[PATCH 3/3] libnvdimm/bus: simplify walk_to_nvdimm_bus()

2020-08-17 Thread Zhen Lei
hing has changed. So it's just source code level optimization, make us can read it faster. Signed-off-by: Zhen Lei --- drivers/nvdimm/bus.c | 7 +++ 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/drivers/nvdimm/bus.c b/drivers/nvdimm/bus.c index 955265656b96c73..1d89114cb6ab9

[PATCH v2 2/4] libnvdimm: add sanity check for provider_name in of_pmem_region_probe()

2020-08-18 Thread Zhen Lei
kstrdup() may return NULL because of no memory, check it. Fixes: 49bddc73d15c ("libnvdimm/of_pmem: Provide a unique name for bus provider") Signed-off-by: Zhen Lei --- drivers/nvdimm/of_pmem.c | 5 + 1 file changed, 5 insertions(+) diff --git a/drivers/nvdimm/of_pmem.c b/driv

[PATCH v2 1/4] libnvdimm: fix memmory leaks in of_pmem.c

2020-08-18 Thread Zhen Lei
The memory priv->bus_desc.provider_name allocated by kstrdup() is not freed correctly. Fixes: 49bddc73d15c ("libnvdimm/of_pmem: Provide a unique name for bus provider") Signed-off-by: Zhen Lei --- drivers/nvdimm/of_pmem.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/d

[PATCH v2 0/4] bugfix and optimize for drivers/nvdimm

2020-08-18 Thread Zhen Lei
ecause strdup() maybe failed. Patch 3 is a trivial source code optimization. Zhen Lei (4): libnvdimm: fix memmory leaks in of_pmem.c libnvdimm: add sanity check for provider_name in of_pmem_region_probe() libnvdimm/bus: simplify walk_to_nvdimm_bus() libnvdimm/region: reduce an unnec

[PATCH v2 3/4] libnvdimm/bus: simplify walk_to_nvdimm_bus()

2020-08-18 Thread Zhen Lei
hing has changed. So it's just source code level optimization, make us can read it faster. Signed-off-by: Zhen Lei --- drivers/nvdimm/bus.c | 7 +++ 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/drivers/nvdimm/bus.c b/drivers/nvdimm/bus.c index 955265656b96c73..1d89114cb6ab9

[PATCH v2 4/4] libnvdimm/region: reduce an unnecessary if branch in nd_region_create()

2020-08-18 Thread Zhen Lei
The "else" branch can only be entered when ndr_desc->flush is NULL. After replaced "NULL" with "ndr_desc->flush", we will find that the statements in "if..else.." are the same. No functional change. Signed-off-by: Zhen Lei --- drivers/nvdimm/region

[PATCH 3/4] libnvdimm: eliminate two unnecessary zero initializations in badrange.c

2020-08-20 Thread Zhen Lei
hat means, the kzalloc() in badrange_add() or alloc_and_append_badrange_entry() can be replaced with kmalloc(), because the zero initialization is not required. Signed-off-by: Zhen Lei --- drivers/nvdimm/badrange.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/nvdimm/badrange.c b/drivers

[PATCH 2/4] libnvdimm: eliminate a meaningless spinlock operation

2020-08-20 Thread Zhen Lei
lock protection. Fixes: b3b454f694db ("libnvdimm: fix clear poison locking with spinlock ...") Signed-off-by: Zhen Lei --- drivers/nvdimm/badrange.c | 22 -- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/drivers/nvdimm/badrange.c b/drivers/nvdimm

[PATCH 0/4] clean up some functions in nvdimm/badrange.c and namespace_devs.c

2020-08-20 Thread Zhen Lei
When I learned the code of drivers/nvdimm, I found some places can be improved. Zhen Lei (4): libnvdimm: remove redundant list_empty() check in badrange.c libnvdimm: eliminate a meaningless spinlock operation libnvdimm: eliminate two unnecessary zero initializations in badrange.c

[PATCH 4/4] libnvdimm: avoid unnecessary judgments in nvdimm_namespace_disk_name()

2020-08-20 Thread Zhen Lei
size. Before: textdata bss dec hex filename 417493697 16 45462b196 drivers/nvdimm/namespace_devs.o After: textdata bss dec hex filename 416533697 16 45366b136 drivers/nvdimm/namespace_devs.o Signed-off-by: Zhen Lei --- driver

[PATCH 1/4] libnvdimm: remove redundant list_empty() check in badrange.c

2020-08-20 Thread Zhen Lei
list_for_each_entry() to do it. Signed-off-by: Zhen Lei --- drivers/nvdimm/badrange.c | 10 -- 1 file changed, 10 deletions(-) diff --git a/drivers/nvdimm/badrange.c b/drivers/nvdimm/badrange.c index b9eeefa27e3a507..9fdba8c43e8605e 100644 --- a/drivers/nvdimm/badrange.c +++ b/drivers/nvdimm/badrange.c

[PATCH v3 0/7] bugfix and optimize for drivers/nvdimm

2020-08-19 Thread Zhen Lei
desc.provider_name, because strdup() maybe failed. Patch 3 is a trivial source code optimization. Zhen Lei (7): libnvdimm: fix memory leaks in of_pmem.c libnvdimm: add sanity check for provider_name in of_pmem_region_probe() libnvdimm: simplify walk_to_nvdimm_bus() libnvdimm: reduce an

[PATCH v3 4/7] libnvdimm: reduce an unnecessary if branch in nd_region_create()

2020-08-19 Thread Zhen Lei
comes the same to 1). So the above code snippet can be reduced to one statement: nd_region->flush = ndr_desc->flush; No functional change. Signed-off-by: Zhen Lei --- drivers/nvdimm/region_devs.c | 5 + 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/drivers/nvd

[PATCH v3 3/7] libnvdimm: simplify walk_to_nvdimm_bus()

2020-08-19 Thread Zhen Lei
Return as soon as nvdimm_bus device has been found, make us no need to check "dev" or "!dev" in subsequent code. No functional change. Signed-off-by: Zhen Lei --- drivers/nvdimm/bus.c | 7 +++ 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/drivers/nv

[PATCH v3 7/7] libnvdimm: slightly simplify available_slots_show()

2020-08-19 Thread Zhen Lei
The type of "nfree" is u32, so "nfree - 1" can only be overflowed when "nfree" is zero. Replace "if (nfree - 1 > nfree)" with "if (nfree == 0)" seems more clear. And remove the assignment "nfree = 0", no need for it. Signed-off-

[PATCH v3 2/7] libnvdimm: add sanity check for provider_name in of_pmem_region_probe()

2020-08-19 Thread Zhen Lei
kstrdup() may return NULL because of no memory, check it. Fixes: 49bddc73d15c ("libnvdimm/of_pmem: Provide a unique name for bus provider") Signed-off-by: Zhen Lei --- drivers/nvdimm/of_pmem.c | 5 + 1 file changed, 5 insertions(+) diff --git a/drivers/nvdimm/of_pmem.c b/driv

[PATCH v3 1/7] libnvdimm: fix memory leaks in of_pmem.c

2020-08-19 Thread Zhen Lei
Currently, in the last error path of of_pmem_region_probe() and in of_pmem_region_remove(), free the memory allocated by kstrdup() is missing. Add kfree(priv->bus_desc.provider_name) to fix it. Fixes: 49bddc73d15c ("libnvdimm/of_pmem: Provide a unique name for bus provider") Signed

[PATCH v3 6/7] libnvdimm: make sure EXPORT_SYMBOL_GPL(nvdimm_flush) close to its function

2020-08-19 Thread Zhen Lei
Move EXPORT_SYMBOL_GPL(nvdimm_flush) close to nvdimm_flush(), currently it's near to generic_nvdimm_flush(). Signed-off-by: Zhen Lei --- drivers/nvdimm/region_devs.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/nvdimm/region_devs.c b/drivers/nvdimm/region_devs.c

[PATCH v3 5/7] libnvdimm: reduce an unnecessary if branch in nd_region_activate()

2020-08-19 Thread Zhen Lei
zeof(void *); } Obviously, the above code snippet can be reduced to one statement: flush_data_size += (nvdimm->num_flush + 1) * sizeof(void *); No functional change. Signed-off-by: Zhen Lei --- drivers/nvdimm/region_devs.c | 5 + 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/dr

[PATCH 1/1] device-dax: fix mismatches of request_mem_region()

2020-08-17 Thread Zhen Lei
The resources allocated by request_mem_region() is better to use release_mem_region() to free. These two functions are paired. Signed-off-by: Zhen Lei --- drivers/dax/kmem.c | 6 ++ 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/drivers/dax/kmem.c b/drivers/dax/kmem.c index

[PATCH v2 1/1] libnvdimm/region: delete a piece of useless code in nd_region_create()

2020-09-19 Thread Zhen Lei
t; with "ndr_desc->flush" at 2), we will find that it becomes the same to 1). So the above code snippet can be reduced to one statement: nd_region->flush = ndr_desc->flush; No functional change. Signed-off-by: Zhen Lei --- v1 --> v2: 1. Only the title and description are modi

[PATCH v2 1/1] libnvdimm/namespace: avoid repeated judgment in nvdimm_namespace_disk_name()

2020-09-19 Thread Zhen Lei
96 drivers/nvdimm/namespace_devs.o After: textdata bss dec hex filename 416533697 16 45366b136 drivers/nvdimm/namespace_devs.o Signed-off-by: Zhen Lei --- v1 --> v2: 1. Only the title and description are modified. v1: https://lore.kernel.org/patchwork/

[PATCH v2 2/2] libnvdimm/badrange: eliminate a meaningless spinlock operation

2020-09-19 Thread Zhen Lei
eaningless. Because the static function add_badrange() is only called by badrange_add(), so move its content into badrange_add() then delete it. By the way, move "kfree(bre_new)" out of the lock protection, it really doesn't need. Fixes: b3b454f694db ("libnvdimm: fix clear poison l

[PATCH v2 0/2] libnvdimm/badrange: simplify code

2020-09-19 Thread Zhen Lei
v1 --> v2: 1. Only the titles and descriptions are modified. v1: https://lore.kernel.org/patchwork/cover/1292582/Patch 1-2 Zhen Lei (2): libnvdimm/badrange: remove two redundant list_empty() branches libnvdimm/badrange: eliminate a meaningless spinlock operation drivers/nvd

[PATCH v2 1/2] libnvdimm/badrange: remove two redundant list_empty() branches

2020-09-19 Thread Zhen Lei
() do things-B //can only be entered if !list_empty() 3) do things-A return Y; It's very clear that, the processing result after deleting 1) is the same as that before deleting 1). So delete 1) to simplify code. Signed-off-by: Zhen Lei --- drivers/nvdimm/badrange.c | 10

[PATCH v2 1/1] libnvdimm: make sure EXPORT_SYMBOL_GPL(nvdimm_flush) close to its function

2020-09-19 Thread Zhen Lei
Move EXPORT_SYMBOL_GPL(nvdimm_flush) close to nvdimm_flush(), currently it's near to generic_nvdimm_flush(). Signed-off-by: Zhen Lei Reviewed-by: Pankaj Gupta --- v1 --> v2 1. add "Reviewed-by: Pankaj Gupta " v1: https://lkml.org/lkml/2020/8/20/904 drivers/nvdimm/region_devs

[PATCH v2 1/1] libnvdimm: slightly simplify available_slots_show()

2020-09-19 Thread Zhen Lei
The type of "nfree" is u32, so "nfree - 1" can only be overflowed when "nfree" is zero. Replace "if (nfree - 1 > nfree)" with "if (nfree == 0)" seems more clear. And remove the assignment "nfree = 0", no need for it. Signed-off-b

[PATCH v2 1/1] libnvdimm/namespace: avoid repeated judgment in nvdimm_namespace_disk_name()

2020-09-19 Thread Zhen Lei
96 drivers/nvdimm/namespace_devs.o After: textdata bss dec hex filename 416533697 16 45366b136 drivers/nvdimm/namespace_devs.o Signed-off-by: Zhen Lei --- v1 --> v2: 1. Only the title and description are modified. v1: https://lore.kernel.org/patchwork/

[PATCH v2 0/1] device-dax: avoid an unnecessary check in alloc_dev_dax_range()

2020-12-19 Thread Zhen Lei
v1 --> v2: In v1, I use the "goto" statement to merge two identical __release_region() calls. However, the new patch https://lkml.org/lkml/2020/12/18/735 deletes one of them, the "goto" becomes worthless. So when krealloc() failed, directly call __release_region() and re

[PATCH v2 1/1] device-dax: avoid an unnecessary check in alloc_dev_dax_range()

2020-12-19 Thread Zhen Lei
Swap the calling sequence of krealloc() and __request_region(), call the latter first. In this way, the value of dev_dax->nr_range does not need to be considered when __request_region() failed. Signed-off-by: Zhen Lei --- drivers/dax/bus.c | 20 ++-- 1 file changed, 6 inserti

[PATCH 1/1] device-dax: avoid an unnecessary check in alloc_dev_dax_range()

2020-11-20 Thread Zhen Lei
Swap the calling sequence of krealloc() and __request_region(), call the latter first. In this way, the value of dev_dax->nr_range does not need to be considered when __request_region() failed. Signed-off-by: Zhen Lei --- drivers/dax/bus.c | 29 - 1 file changed,

[PATCH 1/1] device-dax: delete a redundancy check in dev_dax_validate_align()

2020-11-20 Thread Zhen Lei
After we have done the alignment check for the length of each range, the alignment check for dev_dax_size(dev_dax) is no longer needed, because it get the sum of the length of each range. Signed-off-by: Zhen Lei --- drivers/dax/bus.c | 7 --- 1 file changed, 7 deletions(-) diff --git

[PATCH 1/1] ACPI/nfit: correct the badrange to be reported in nfit_handle_mce()

2020-11-18 Thread Zhen Lei
The badrange to be reported should always cover mce->addr. Signed-off-by: Zhen Lei --- drivers/acpi/nfit/mce.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/acpi/nfit/mce.c b/drivers/acpi/nfit/mce.c index ee8d9973f60b..053e719c7bea 100644 --- a/drivers/acpi/n

[PATCH v2 1/1] acpi/nfit: fix badrange insertion in nfit_handle_mce()

2020-11-18 Thread Zhen Lei
Make sure the badrange to be reported can always cover mce->addr. Fixes: 9ffd6350a103 ("nfit: don't start a full scrub by default for an MCE") Signed-off-by: Zhen Lei Reviewed-by: Vishal Verma --- drivers/acpi/nfit/mce.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-

[PATCH v2 0/1] acpi/nfit: fix badrange insertion in nfit_handle_mce()

2020-11-18 Thread Zhen Lei
v1 --> v2: Modified the title and description of the patch. Zhen Lei (1): acpi/nfit: fix badrange insertion in nfit_handle_mce() drivers/acpi/nfit/mce.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) -- 2.26.0.106.g9fadedd ___ Linux-nvd

[PATCH 1/1] ACPI/nfit: avoid accessing uninitialized memory in acpi_nfit_ctl()

2020-11-17 Thread Zhen Lei
The ACPI_ALLOCATE() does not zero the "buf", so when the condition "integer->type != ACPI_TYPE_INTEGER" in int_to_buf() is met, the result is unpredictable in acpi_nfit_ctl(). Signed-off-by: Zhen Lei --- drivers/acpi/nfit/core.c | 9 + 1 file changed, 5 ins