Message ID | 20221008093942.3982-1-xupengfei@nfschina.com (mailing list archive) |
---|---|
State | New |
Headers | show |
Series | [1/1] mm/mmap_lock: Remove unnecessary 'NULL' values from Pointer | expand |
On 2022/10/8 17:39, XU pengfei wrote: > Pointer variables allocate memory first, and then judge. There is no > need to initialize the assignment. > > Signed-off-by: XU pengfei <xupengfei@nfschina.com> > --- > mm/mmap_lock.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/mm/mmap_lock.c b/mm/mmap_lock.c > index 1854850b4b89..65a57731aa15 100644 > --- a/mm/mmap_lock.c > +++ b/mm/mmap_lock.c > @@ -198,7 +198,7 @@ void trace_mmap_lock_unreg(void) > */ > static const char *get_mm_memcg_path(struct mm_struct *mm) > { > - char *buf = NULL; > + char *buf; > struct mem_cgroup *memcg = get_mem_cgroup_from_mm(mm); > > if (memcg == NULL) It seems if memcg == NULL, the code will go to out and return uninitialized @buf? Thanks, Miaohe Lin
Hi XU,
Thank you for the patch! Perhaps something to improve:
[auto build test WARNING on akpm-mm/mm-everything]
url: https://github.com/intel-lab-lkp/linux/commits/XU-pengfei/mm-mmap_lock-Remove-unnecessary-NULL-values-from-Pointer/20221008-174149
base: https://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm.git mm-everything
config: x86_64-randconfig-a003-20221003
compiler: clang version 14.0.6 (https://github.com/llvm/llvm-project f28c006a5895fc0e329fe15fead81e37457cb1d1)
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# https://github.com/intel-lab-lkp/linux/commit/d8ed9ca4f5c0538ddfb42265c5f91cc185aa0507
git remote add linux-review https://github.com/intel-lab-lkp/linux
git fetch --no-tags linux-review XU-pengfei/mm-mmap_lock-Remove-unnecessary-NULL-values-from-Pointer/20221008-174149
git checkout d8ed9ca4f5c0538ddfb42265c5f91cc185aa0507
# save the config file
mkdir build_dir && cp config build_dir/.config
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=x86_64 SHELL=/bin/bash
If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <lkp@intel.com>
All warnings (new ones prefixed by >>):
>> mm/mmap_lock.c:206:6: warning: variable 'buf' is used uninitialized whenever 'if' condition is true [-Wsometimes-uninitialized]
if (unlikely(memcg->css.cgroup == NULL))
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
include/linux/compiler.h:78:22: note: expanded from macro 'unlikely'
# define unlikely(x) __builtin_expect(!!(x), 0)
^~~~~~~~~~~~~~~~~~~~~~~~~~
mm/mmap_lock.c:218:9: note: uninitialized use occurs here
return buf;
^~~
mm/mmap_lock.c:206:2: note: remove the 'if' if its condition is always false
if (unlikely(memcg->css.cgroup == NULL))
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
mm/mmap_lock.c:204:6: warning: variable 'buf' is used uninitialized whenever 'if' condition is true [-Wsometimes-uninitialized]
if (memcg == NULL)
^~~~~~~~~~~~~
mm/mmap_lock.c:218:9: note: uninitialized use occurs here
return buf;
^~~
mm/mmap_lock.c:204:2: note: remove the 'if' if its condition is always false
if (memcg == NULL)
^~~~~~~~~~~~~~~~~~
mm/mmap_lock.c:201:11: note: initialize the variable 'buf' to silence this warning
char *buf;
^
= NULL
2 warnings generated.
vim +206 mm/mmap_lock.c
d01079f3d0c0a9 Mel Gorman 2021-06-30 184
d01079f3d0c0a9 Mel Gorman 2021-06-30 185 #ifdef CONFIG_TRACING
d01079f3d0c0a9 Mel Gorman 2021-06-30 186 #ifdef CONFIG_MEMCG
2b5067a8143e34 Axel Rasmussen 2020-12-14 187 /*
2b5067a8143e34 Axel Rasmussen 2020-12-14 188 * Write the given mm_struct's memcg path to a percpu buffer, and return a
2b5067a8143e34 Axel Rasmussen 2020-12-14 189 * pointer to it. If the path cannot be determined, or no buffer was available
2b5067a8143e34 Axel Rasmussen 2020-12-14 190 * (because the trace event is being unregistered), NULL is returned.
2b5067a8143e34 Axel Rasmussen 2020-12-14 191 *
2b5067a8143e34 Axel Rasmussen 2020-12-14 192 * Note: buffers are allocated per-cpu to avoid locking, so preemption must be
2b5067a8143e34 Axel Rasmussen 2020-12-14 193 * disabled by the caller before calling us, and re-enabled only after the
2b5067a8143e34 Axel Rasmussen 2020-12-14 194 * caller is done with the pointer.
2b5067a8143e34 Axel Rasmussen 2020-12-14 195 *
2b5067a8143e34 Axel Rasmussen 2020-12-14 196 * The caller must call put_memcg_path_buf() once the buffer is no longer
2b5067a8143e34 Axel Rasmussen 2020-12-14 197 * needed. This must be done while preemption is still disabled.
2b5067a8143e34 Axel Rasmussen 2020-12-14 198 */
2b5067a8143e34 Axel Rasmussen 2020-12-14 199 static const char *get_mm_memcg_path(struct mm_struct *mm)
2b5067a8143e34 Axel Rasmussen 2020-12-14 200 {
d8ed9ca4f5c053 XU pengfei 2022-10-08 201 char *buf;
2b5067a8143e34 Axel Rasmussen 2020-12-14 202 struct mem_cgroup *memcg = get_mem_cgroup_from_mm(mm);
2b5067a8143e34 Axel Rasmussen 2020-12-14 203
2b5067a8143e34 Axel Rasmussen 2020-12-14 204 if (memcg == NULL)
2b5067a8143e34 Axel Rasmussen 2020-12-14 205 goto out;
2b5067a8143e34 Axel Rasmussen 2020-12-14 @206 if (unlikely(memcg->css.cgroup == NULL))
2b5067a8143e34 Axel Rasmussen 2020-12-14 207 goto out_put;
2b5067a8143e34 Axel Rasmussen 2020-12-14 208
2b5067a8143e34 Axel Rasmussen 2020-12-14 209 buf = get_memcg_path_buf();
2b5067a8143e34 Axel Rasmussen 2020-12-14 210 if (buf == NULL)
2b5067a8143e34 Axel Rasmussen 2020-12-14 211 goto out_put;
2b5067a8143e34 Axel Rasmussen 2020-12-14 212
2b5067a8143e34 Axel Rasmussen 2020-12-14 213 cgroup_path(memcg->css.cgroup, buf, MEMCG_PATH_BUF_SIZE);
2b5067a8143e34 Axel Rasmussen 2020-12-14 214
2b5067a8143e34 Axel Rasmussen 2020-12-14 215 out_put:
2b5067a8143e34 Axel Rasmussen 2020-12-14 216 css_put(&memcg->css);
2b5067a8143e34 Axel Rasmussen 2020-12-14 217 out:
2b5067a8143e34 Axel Rasmussen 2020-12-14 218 return buf;
2b5067a8143e34 Axel Rasmussen 2020-12-14 219 }
2b5067a8143e34 Axel Rasmussen 2020-12-14 220
diff --git a/mm/mmap_lock.c b/mm/mmap_lock.c index 1854850b4b89..65a57731aa15 100644 --- a/mm/mmap_lock.c +++ b/mm/mmap_lock.c @@ -198,7 +198,7 @@ void trace_mmap_lock_unreg(void) */ static const char *get_mm_memcg_path(struct mm_struct *mm) { - char *buf = NULL; + char *buf; struct mem_cgroup *memcg = get_mem_cgroup_from_mm(mm); if (memcg == NULL)
Pointer variables allocate memory first, and then judge. There is no need to initialize the assignment. Signed-off-by: XU pengfei <xupengfei@nfschina.com> --- mm/mmap_lock.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)