All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] mm: Use BUG_ON directly instead of a if condition followed by BUG
@ 2018-09-10 14:03 ` zhong jiang
  0 siblings, 0 replies; 4+ messages in thread
From: zhong jiang @ 2018-09-10 14:03 UTC (permalink / raw)
  To: akpm; +Cc: mhocko, pasha.tatashin, dan.j.williams, linux-mm, linux-kernel

The if condition can be removed if we use BUG_ON directly.
The issule is detected with the help of Coccinelle.

Signed-off-by: zhong jiang <zhongjiang@huawei.com>
---
 mm/memory_hotplug.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c
index 38d94b7..280b26c 100644
--- a/mm/memory_hotplug.c
+++ b/mm/memory_hotplug.c
@@ -1888,8 +1888,7 @@ void __ref remove_memory(int nid, u64 start, u64 size)
 	 */
 	ret = walk_memory_range(PFN_DOWN(start), PFN_UP(start + size - 1), NULL,
 				check_memblock_offlined_cb);
-	if (ret)
-		BUG();
+	BUG(ret);
 
 	/* remove memmap entry */
 	firmware_map_remove(start, start + size, "System RAM");
-- 
1.7.12.4


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH] mm: Use BUG_ON directly instead of a if condition followed by BUG
@ 2018-09-10 14:03 ` zhong jiang
  0 siblings, 0 replies; 4+ messages in thread
From: zhong jiang @ 2018-09-10 14:03 UTC (permalink / raw)
  To: akpm; +Cc: mhocko, pasha.tatashin, dan.j.williams, linux-mm, linux-kernel

The if condition can be removed if we use BUG_ON directly.
The issule is detected with the help of Coccinelle.

Signed-off-by: zhong jiang <zhongjiang@huawei.com>
---
 mm/memory_hotplug.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c
index 38d94b7..280b26c 100644
--- a/mm/memory_hotplug.c
+++ b/mm/memory_hotplug.c
@@ -1888,8 +1888,7 @@ void __ref remove_memory(int nid, u64 start, u64 size)
 	 */
 	ret = walk_memory_range(PFN_DOWN(start), PFN_UP(start + size - 1), NULL,
 				check_memblock_offlined_cb);
-	if (ret)
-		BUG();
+	BUG(ret);
 
 	/* remove memmap entry */
 	firmware_map_remove(start, start + size, "System RAM");
-- 
1.7.12.4

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] mm: Use BUG_ON directly instead of a if condition followed by BUG
  2018-09-10 14:03 ` zhong jiang
  (?)
@ 2018-09-10 14:27 ` Michal Hocko
  -1 siblings, 0 replies; 4+ messages in thread
From: Michal Hocko @ 2018-09-10 14:27 UTC (permalink / raw)
  To: zhong jiang; +Cc: akpm, pasha.tatashin, dan.j.williams, linux-mm, linux-kernel

On Mon 10-09-18 22:03:17, zhong jiang wrote:
> The if condition can be removed if we use BUG_ON directly.
> The issule is detected with the help of Coccinelle.

typo here

Is this really worth changing? If anything I would really love to see
the BUG_ON going away rather than make a cosmetic changes to it.

> Signed-off-by: zhong jiang <zhongjiang@huawei.com>
> ---
>  mm/memory_hotplug.c | 3 +--
>  1 file changed, 1 insertion(+), 2 deletions(-)
> 
> diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c
> index 38d94b7..280b26c 100644
> --- a/mm/memory_hotplug.c
> +++ b/mm/memory_hotplug.c
> @@ -1888,8 +1888,7 @@ void __ref remove_memory(int nid, u64 start, u64 size)
>  	 */
>  	ret = walk_memory_range(PFN_DOWN(start), PFN_UP(start + size - 1), NULL,
>  				check_memblock_offlined_cb);
> -	if (ret)
> -		BUG();
> +	BUG(ret);
>  
>  	/* remove memmap entry */
>  	firmware_map_remove(start, start + size, "System RAM");
> -- 
> 1.7.12.4
> 

-- 
Michal Hocko
SUSE Labs

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] mm: Use BUG_ON directly instead of a if condition followed by BUG
  2018-09-10 14:03 ` zhong jiang
  (?)
  (?)
@ 2018-09-10 19:54 ` kbuild test robot
  -1 siblings, 0 replies; 4+ messages in thread
From: kbuild test robot @ 2018-09-10 19:54 UTC (permalink / raw)
  To: zhong jiang
  Cc: kbuild-all, akpm, mhocko, pasha.tatashin, dan.j.williams,
	linux-mm, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 2156 bytes --]

Hi zhong,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on linus/master]
[also build test ERROR on v4.19-rc3 next-20180910]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]

url:    https://github.com/0day-ci/linux/commits/zhong-jiang/mm-Use-BUG_ON-directly-instead-of-a-if-condition-followed-by-BUG/20180911-025008
config: x86_64-randconfig-x012-201836 (attached as .config)
compiler: gcc-7 (Debian 7.3.0-1) 7.3.0
reproduce:
        # save the attached .config to linux build tree
        make ARCH=x86_64 

All errors (new ones prefixed by >>):

   mm/memory_hotplug.c: In function 'remove_memory':
>> mm/memory_hotplug.c:1891:9: error: macro "BUG" passed 1 arguments, but takes just 0
     BUG(ret);
            ^
>> mm/memory_hotplug.c:1891:2: error: 'BUG' undeclared (first use in this function)
     BUG(ret);
     ^~~
   mm/memory_hotplug.c:1891:2: note: each undeclared identifier is reported only once for each function it appears in

vim +/BUG +1891 mm/memory_hotplug.c

  1865	
  1866	/**
  1867	 * remove_memory
  1868	 * @nid: the node ID
  1869	 * @start: physical address of the region to remove
  1870	 * @size: size of the region to remove
  1871	 *
  1872	 * NOTE: The caller must call lock_device_hotplug() to serialize hotplug
  1873	 * and online/offline operations before this call, as required by
  1874	 * try_offline_node().
  1875	 */
  1876	void __ref remove_memory(int nid, u64 start, u64 size)
  1877	{
  1878		int ret;
  1879	
  1880		BUG_ON(check_hotplug_memory_range(start, size));
  1881	
  1882		mem_hotplug_begin();
  1883	
  1884		/*
  1885		 * All memory blocks must be offlined before removing memory.  Check
  1886		 * whether all memory blocks in question are offline and trigger a BUG()
  1887		 * if this is not the case.
  1888		 */
  1889		ret = walk_memory_range(PFN_DOWN(start), PFN_UP(start + size - 1), NULL,
  1890					check_memblock_offlined_cb);
> 1891		BUG(ret);

---
0-DAY kernel test infrastructure                Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all                   Intel Corporation

[-- Attachment #2: .config.gz --]
[-- Type: application/gzip, Size: 31308 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2018-09-10 19:54 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-09-10 14:03 [PATCH] mm: Use BUG_ON directly instead of a if condition followed by BUG zhong jiang
2018-09-10 14:03 ` zhong jiang
2018-09-10 14:27 ` Michal Hocko
2018-09-10 19:54 ` kbuild test robot

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.