* [PATCH 0/2] nvdimm deadcoding
@ 2025-02-20 0:45 linux
2025-02-20 0:45 ` [PATCH 1/2] libnvdimm: Remove unused nd_region_conflict linux
` (3 more replies)
0 siblings, 4 replies; 6+ messages in thread
From: linux @ 2025-02-20 0:45 UTC (permalink / raw)
To: dan.j.williams, vishal.l.verma, dave.jiang, ira.weiny
Cc: nvdimm, linux-kernel, Dr. David Alan Gilbert
From: "Dr. David Alan Gilbert" <linux@treblig.org>
Hi,
A couple of nvdimm dead coding patches; they just
remove entirely unused functions.
Signed-off-by: Dr. David Alan Gilbert <linux@treblig.org>
Dr. David Alan Gilbert (2):
libnvdimm: Remove unused nd_region_conflict
libnvdimm: Remove unused nd_attach_ndns
drivers/nvdimm/claim.c | 11 ----------
drivers/nvdimm/nd-core.h | 4 ----
drivers/nvdimm/region_devs.c | 41 ------------------------------------
3 files changed, 56 deletions(-)
--
2.48.1
^ permalink raw reply [flat|nested] 6+ messages in thread* [PATCH 1/2] libnvdimm: Remove unused nd_region_conflict 2025-02-20 0:45 [PATCH 0/2] nvdimm deadcoding linux @ 2025-02-20 0:45 ` linux 2025-02-20 0:45 ` [PATCH 2/2] libnvdimm: Remove unused nd_attach_ndns linux ` (2 subsequent siblings) 3 siblings, 0 replies; 6+ messages in thread From: linux @ 2025-02-20 0:45 UTC (permalink / raw) To: dan.j.williams, vishal.l.verma, dave.jiang, ira.weiny Cc: nvdimm, linux-kernel, Dr. David Alan Gilbert From: "Dr. David Alan Gilbert" <linux@treblig.org> nd_region_conflict() has been unused since 2019's commit a3619190d62e ("libnvdimm/pfn: stop padding pmem namespaces to section alignment") Remove it, and the region_confict() helper it uses, and the associated struct conflict_context. Signed-off-by: Dr. David Alan Gilbert <linux@treblig.org> --- drivers/nvdimm/nd-core.h | 2 -- drivers/nvdimm/region_devs.c | 41 ------------------------------------ 2 files changed, 43 deletions(-) diff --git a/drivers/nvdimm/nd-core.h b/drivers/nvdimm/nd-core.h index 86976a9e8a15..2b37b7fc4fef 100644 --- a/drivers/nvdimm/nd-core.h +++ b/drivers/nvdimm/nd-core.h @@ -127,8 +127,6 @@ resource_size_t nd_region_allocatable_dpa(struct nd_region *nd_region); resource_size_t nd_pmem_available_dpa(struct nd_region *nd_region, struct nd_mapping *nd_mapping); resource_size_t nd_region_available_dpa(struct nd_region *nd_region); -int nd_region_conflict(struct nd_region *nd_region, resource_size_t start, - resource_size_t size); resource_size_t nvdimm_allocated_dpa(struct nvdimm_drvdata *ndd, struct nd_label_id *label_id); int nvdimm_num_label_slots(struct nvdimm_drvdata *ndd); diff --git a/drivers/nvdimm/region_devs.c b/drivers/nvdimm/region_devs.c index 37417ce5ec7b..de1ee5ebc851 100644 --- a/drivers/nvdimm/region_devs.c +++ b/drivers/nvdimm/region_devs.c @@ -1229,45 +1229,4 @@ bool is_nvdimm_sync(struct nd_region *nd_region) } EXPORT_SYMBOL_GPL(is_nvdimm_sync); -struct conflict_context { - struct nd_region *nd_region; - resource_size_t start, size; -}; - -static int region_conflict(struct device *dev, void *data) -{ - struct nd_region *nd_region; - struct conflict_context *ctx = data; - resource_size_t res_end, region_end, region_start; - - if (!is_memory(dev)) - return 0; - - nd_region = to_nd_region(dev); - if (nd_region == ctx->nd_region) - return 0; - - res_end = ctx->start + ctx->size; - region_start = nd_region->ndr_start; - region_end = region_start + nd_region->ndr_size; - if (ctx->start >= region_start && ctx->start < region_end) - return -EBUSY; - if (res_end > region_start && res_end <= region_end) - return -EBUSY; - return 0; -} - -int nd_region_conflict(struct nd_region *nd_region, resource_size_t start, - resource_size_t size) -{ - struct nvdimm_bus *nvdimm_bus = walk_to_nvdimm_bus(&nd_region->dev); - struct conflict_context ctx = { - .nd_region = nd_region, - .start = start, - .size = size, - }; - - return device_for_each_child(&nvdimm_bus->dev, &ctx, region_conflict); -} - MODULE_IMPORT_NS("DEVMEM"); -- 2.48.1 ^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH 2/2] libnvdimm: Remove unused nd_attach_ndns 2025-02-20 0:45 [PATCH 0/2] nvdimm deadcoding linux 2025-02-20 0:45 ` [PATCH 1/2] libnvdimm: Remove unused nd_region_conflict linux @ 2025-02-20 0:45 ` linux 2025-02-20 19:10 ` [PATCH 0/2] nvdimm deadcoding Ira Weiny 2025-02-20 20:37 ` Alison Schofield 3 siblings, 0 replies; 6+ messages in thread From: linux @ 2025-02-20 0:45 UTC (permalink / raw) To: dan.j.williams, vishal.l.verma, dave.jiang, ira.weiny Cc: nvdimm, linux-kernel, Dr. David Alan Gilbert From: "Dr. David Alan Gilbert" <linux@treblig.org> nd_attach_ndns() hasn't been used since 2017's commit 452bae0aede7 ("libnvdimm: fix nvdimm_bus_lock() vs device_lock() ordering") Remove it. Note the __ version is still used and has been left. Signed-off-by: Dr. David Alan Gilbert <linux@treblig.org> --- drivers/nvdimm/claim.c | 11 ----------- drivers/nvdimm/nd-core.h | 2 -- 2 files changed, 13 deletions(-) diff --git a/drivers/nvdimm/claim.c b/drivers/nvdimm/claim.c index 9e84ab411564..51614651d2e7 100644 --- a/drivers/nvdimm/claim.c +++ b/drivers/nvdimm/claim.c @@ -56,17 +56,6 @@ bool __nd_attach_ndns(struct device *dev, struct nd_namespace_common *attach, return true; } -bool nd_attach_ndns(struct device *dev, struct nd_namespace_common *attach, - struct nd_namespace_common **_ndns) -{ - bool claimed; - - nvdimm_bus_lock(&attach->dev); - claimed = __nd_attach_ndns(dev, attach, _ndns); - nvdimm_bus_unlock(&attach->dev); - return claimed; -} - static bool is_idle(struct device *dev, struct nd_namespace_common *ndns) { struct nd_region *nd_region = to_nd_region(dev->parent); diff --git a/drivers/nvdimm/nd-core.h b/drivers/nvdimm/nd-core.h index 2b37b7fc4fef..bfc6bfeb6e24 100644 --- a/drivers/nvdimm/nd-core.h +++ b/drivers/nvdimm/nd-core.h @@ -134,8 +134,6 @@ void get_ndd(struct nvdimm_drvdata *ndd); resource_size_t __nvdimm_namespace_capacity(struct nd_namespace_common *ndns); void nd_detach_ndns(struct device *dev, struct nd_namespace_common **_ndns); void __nd_detach_ndns(struct device *dev, struct nd_namespace_common **_ndns); -bool nd_attach_ndns(struct device *dev, struct nd_namespace_common *attach, - struct nd_namespace_common **_ndns); bool __nd_attach_ndns(struct device *dev, struct nd_namespace_common *attach, struct nd_namespace_common **_ndns); ssize_t nd_namespace_store(struct device *dev, -- 2.48.1 ^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH 0/2] nvdimm deadcoding 2025-02-20 0:45 [PATCH 0/2] nvdimm deadcoding linux 2025-02-20 0:45 ` [PATCH 1/2] libnvdimm: Remove unused nd_region_conflict linux 2025-02-20 0:45 ` [PATCH 2/2] libnvdimm: Remove unused nd_attach_ndns linux @ 2025-02-20 19:10 ` Ira Weiny 2025-02-20 20:37 ` Alison Schofield 3 siblings, 0 replies; 6+ messages in thread From: Ira Weiny @ 2025-02-20 19:10 UTC (permalink / raw) To: linux, dan.j.williams, vishal.l.verma, dave.jiang, ira.weiny Cc: nvdimm, linux-kernel, Dr. David Alan Gilbert linux@ wrote: > From: "Dr. David Alan Gilbert" <linux@treblig.org> > > Hi, > A couple of nvdimm dead coding patches; they just > remove entirely unused functions. > > Signed-off-by: Dr. David Alan Gilbert <linux@treblig.org> For the series. I'll pick these up for 6.15. Reviewed-by: Ira Weiny <ira.weiny@intel.com> > > > Dr. David Alan Gilbert (2): > libnvdimm: Remove unused nd_region_conflict > libnvdimm: Remove unused nd_attach_ndns > > drivers/nvdimm/claim.c | 11 ---------- > drivers/nvdimm/nd-core.h | 4 ---- > drivers/nvdimm/region_devs.c | 41 ------------------------------------ > 3 files changed, 56 deletions(-) > > -- > 2.48.1 > ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 0/2] nvdimm deadcoding 2025-02-20 0:45 [PATCH 0/2] nvdimm deadcoding linux ` (2 preceding siblings ...) 2025-02-20 19:10 ` [PATCH 0/2] nvdimm deadcoding Ira Weiny @ 2025-02-20 20:37 ` Alison Schofield 2025-02-20 21:51 ` Dr. David Alan Gilbert 3 siblings, 1 reply; 6+ messages in thread From: Alison Schofield @ 2025-02-20 20:37 UTC (permalink / raw) To: linux Cc: dan.j.williams, vishal.l.verma, dave.jiang, ira.weiny, nvdimm, linux-kernel On Thu, Feb 20, 2025 at 12:45:36AM +0000, linux@treblig.org wrote: > From: "Dr. David Alan Gilbert" <linux@treblig.org> > > Hi, > A couple of nvdimm dead coding patches; they just > remove entirely unused functions. I see you've been sending patches for dead code removal for several months. What tool are you using for discovery? Thanks, Alison > > Signed-off-by: Dr. David Alan Gilbert <linux@treblig.org> > > > Dr. David Alan Gilbert (2): > libnvdimm: Remove unused nd_region_conflict > libnvdimm: Remove unused nd_attach_ndns > > drivers/nvdimm/claim.c | 11 ---------- > drivers/nvdimm/nd-core.h | 4 ---- > drivers/nvdimm/region_devs.c | 41 ------------------------------------ > 3 files changed, 56 deletions(-) > > -- > 2.48.1 > > ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 0/2] nvdimm deadcoding 2025-02-20 20:37 ` Alison Schofield @ 2025-02-20 21:51 ` Dr. David Alan Gilbert 0 siblings, 0 replies; 6+ messages in thread From: Dr. David Alan Gilbert @ 2025-02-20 21:51 UTC (permalink / raw) To: Alison Schofield Cc: dan.j.williams, vishal.l.verma, dave.jiang, ira.weiny, nvdimm, linux-kernel * Alison Schofield (alison.schofield@intel.com) wrote: > On Thu, Feb 20, 2025 at 12:45:36AM +0000, linux@treblig.org wrote: > > From: "Dr. David Alan Gilbert" <linux@treblig.org> > > > > Hi, > > A couple of nvdimm dead coding patches; they just > > remove entirely unused functions. > > I see you've been sending patches for dead code removal > for several months. What tool are you using for discovery? Hi Alison, Thanks for noticing. I'm using my own very very hacky scripts; notes below. The problem is they generate lots of false-positives so I've got this big output file from one run of the scripts and I then have to go through finding the useful ones. I start with an all-yes-config build on x86, then the script dumps all the relocations using readelf and finds symbols that are defined but don't have any apparent use. (Actually not quite all-yes-config, but close) Then for each of those symbols I grep the whole tree for the symbol and get myself a huge debug file. That means that for each symbol I'm hopefully left where it's defined and declared, and if there are actually any uses that weren't built in my world they show up. Then I gently work through these, look them up with git log -G to find when they were added/stopped being used. On one side there are false positives (stuff only in other builds, so that's why I grep for the symbol name, also symbols that are defined but only used locally in a .o file) There are lots of false negatives as well. But then I have to second guess from the git output a) If it was recently added don't bother, someone is probably about to use it. b) If it's actually a bug and it *should* be called. c) If it's a trivial one liner I don't bother d) If it looks like it's really a wrapper of every firmware call for that device I leave it. e) Skip anything __init etc marked, or look magic (bpf etc) It's tricky because they're all over, so you fall into the preferences of each maitainers oddities of what they care about. My debug file is alphabetically searched; I'm just near the end of the n's - a while to go! I'm hoping once I get to the end, then it'll be a bit cleaner and I can tidy the scripts up and watch for new entries in each release. For reference for the nvdimm symbols my output file looks like: ---- nd_attach_ndns[^A-Z_a-z] ---- drivers/nvdimm/claim.c:44:bool __nd_attach_ndns(struct device *dev, struct nd_namespace_common *attach, drivers/nvdimm/claim.c:59:bool nd_attach_ndns(struct device *dev, struct nd_namespace_common *attach, drivers/nvdimm/claim.c:65: claimed = __nd_attach_ndns(dev, attach, _ndns); drivers/nvdimm/claim.c:216: if (!__nd_attach_ndns(dev, ndns, _ndns)) { drivers/nvdimm/nd-core.h:139:bool nd_attach_ndns(struct device *dev, struct nd_namespace_common *attach, drivers/nvdimm/nd-core.h:141:bool __nd_attach_ndns(struct device *dev, struct nd_namespace_common *attach, drivers/nvdimm/btt_devs.c:211: if (ndns && !__nd_attach_ndns(&nd_btt->dev, ndns, &nd_btt->ndns)) { drivers/nvdimm/pfn_devs.c:311: if (ndns && !__nd_attach_ndns(&nd_pfn->dev, ndns, &nd_pfn->ndns)) { ---- nd_region_conflict[^A-Z_a-z] ---- drivers/nvdimm/nd-core.h:130:int nd_region_conflict(struct nd_region *nd_region, resource_size_t start, drivers/nvdimm/region_devs.c:1260:int nd_region_conflict(struct nd_region *nd_region, resource_size_t start, Scripts (Which I've not run for a few months, I'm still working through the first main run) I start with: find . -name \*.o -exec ~/sym/dosyms {} \; of which dosyms is: -------- echo $1 DIR=$(dirname $1) NEWN=$DIR/$(basename -s .o $1).x readelf -W -s -r $1 | awk -f ~/sym/relocs.awk |sort|uniq > $NEWN -------- so that gets me a load of .x files, which I run through awk -f ~/sym/collate.awk $(find . -name \*.x) > col of which collate.awk is: -------- { if (($1=="u") || ($1=="U")) { use[$2]=use[$2] "," FILENAME usecount[$2]++ } else { def[$2]=def[$2] ",:" $1 ":" FILENAME defcount[$2]++ } } END { for (s in def) { if (usecount[s] == 0) { printf("%s:%d: %s from %s\n", s, usecount[s], use[s], def[s]) } } } -------- Then the following magic: cut -d' ' -f1 col | sed -e 's/:.*/[^A-Z_a-z]/' | while read SYM; do echo $SYM; ag -s --ignore '*.x' --ignore col --ignore col2 "$SYM" < /dev/null; done > search.out which gives the output shown above. (ag is a fast parallel grep, 'the-silver-searcher' ) > Thanks, > Alison Have fun, Dave > > > > > Signed-off-by: Dr. David Alan Gilbert <linux@treblig.org> > > > > > > Dr. David Alan Gilbert (2): > > libnvdimm: Remove unused nd_region_conflict > > libnvdimm: Remove unused nd_attach_ndns > > > > drivers/nvdimm/claim.c | 11 ---------- > > drivers/nvdimm/nd-core.h | 4 ---- > > drivers/nvdimm/region_devs.c | 41 ------------------------------------ > > 3 files changed, 56 deletions(-) > > > > -- > > 2.48.1 > > > > -- -----Open up your eyes, open up your mind, open up your code ------- / Dr. David Alan Gilbert | Running GNU/Linux | Happy \ \ dave @ treblig.org | | In Hex / \ _________________________|_____ http://www.treblig.org |_______/ ^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2025-02-20 21:51 UTC | newest] Thread overview: 6+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2025-02-20 0:45 [PATCH 0/2] nvdimm deadcoding linux 2025-02-20 0:45 ` [PATCH 1/2] libnvdimm: Remove unused nd_region_conflict linux 2025-02-20 0:45 ` [PATCH 2/2] libnvdimm: Remove unused nd_attach_ndns linux 2025-02-20 19:10 ` [PATCH 0/2] nvdimm deadcoding Ira Weiny 2025-02-20 20:37 ` Alison Schofield 2025-02-20 21:51 ` Dr. David Alan Gilbert
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.