All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] ax25: use GFP_KERNEL over GFP_ATOMIC where possible
@ 2022-06-02 11:21 Peter Lafreniere
  2022-06-03  2:47 ` Jakub Kicinski
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Peter Lafreniere @ 2022-06-02 11:21 UTC (permalink / raw)
  To: linux-hams; +Cc: ralf, netdev, Peter Lafreniere

There are a few functions that can sleep that use GFP_ATOMIC.
Here we change allocations to use the more reliable GFP_KERNEL
flag.

ax25_dev_device_up() is only called during device setup, which is
done in user context. In addition, ax25_dev_device_up()
unconditionally calls ax25_register_dev_sysctl(), which already
allocates with GFP_KERNEL.

ax25_rt_add() is a static function that is only called from
ax25_rt_ioctl(), which must run in user context already due to
copy_from_user() usage.

Since it is allowed to sleep in both of these functions, here we
change the functions to use GFP_KERNEL to reduce unnecessary
out-of-memory errors.

Signed-off-by: Peter Lafreniere <pjlafren@mtu.edu>
---
 net/ax25/ax25_dev.c   | 4 ++--
 net/ax25/ax25_route.c | 4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/net/ax25/ax25_dev.c b/net/ax25/ax25_dev.c
index d2a244e1c260..b264904980a8 100644
--- a/net/ax25/ax25_dev.c
+++ b/net/ax25/ax25_dev.c
@@ -52,7 +52,7 @@ void ax25_dev_device_up(struct net_device *dev)
 {
 	ax25_dev *ax25_dev;
 
-	if ((ax25_dev = kzalloc(sizeof(*ax25_dev), GFP_ATOMIC)) == NULL) {
+	if ((ax25_dev = kzalloc(sizeof(*ax25_dev), GFP_KERNEL)) == NULL) {
 		printk(KERN_ERR "AX.25: ax25_dev_device_up - out of memory\n");
 		return;
 	}
@@ -60,7 +60,7 @@ void ax25_dev_device_up(struct net_device *dev)
 	refcount_set(&ax25_dev->refcount, 1);
 	dev->ax25_ptr     = ax25_dev;
 	ax25_dev->dev     = dev;
-	dev_hold_track(dev, &ax25_dev->dev_tracker, GFP_ATOMIC);
+	dev_hold_track(dev, &ax25_dev->dev_tracker, GFP_KERNEL);
 	ax25_dev->forward = NULL;
 
 	ax25_dev->values[AX25_VALUES_IPDEFMODE] = AX25_DEF_IPDEFMODE;
diff --git a/net/ax25/ax25_route.c b/net/ax25/ax25_route.c
index b7c4d656a94b..c77b848ccfc7 100644
--- a/net/ax25/ax25_route.c
+++ b/net/ax25/ax25_route.c
@@ -91,7 +91,7 @@ static int __must_check ax25_rt_add(struct ax25_routes_struct *route)
 			kfree(ax25_rt->digipeat);
 			ax25_rt->digipeat = NULL;
 			if (route->digi_count != 0) {
-				if ((ax25_rt->digipeat = kmalloc(sizeof(ax25_digi), GFP_ATOMIC)) == NULL) {
+				if ((ax25_rt->digipeat = kmalloc(sizeof(ax25_digi), GFP_KERNEL)) == NULL) {
 					write_unlock_bh(&ax25_route_lock);
 					ax25_dev_put(ax25_dev);
 					return -ENOMEM;
@@ -110,7 +110,7 @@ static int __must_check ax25_rt_add(struct ax25_routes_struct *route)
 		ax25_rt = ax25_rt->next;
 	}
 
-	if ((ax25_rt = kmalloc(sizeof(ax25_route), GFP_ATOMIC)) == NULL) {
+	if ((ax25_rt = kmalloc(sizeof(ax25_route), GFP_KERNEL)) == NULL) {
 		write_unlock_bh(&ax25_route_lock);
 		ax25_dev_put(ax25_dev);
 		return -ENOMEM;
-- 
2.36.1


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

* Re: [PATCH] ax25: use GFP_KERNEL over GFP_ATOMIC where possible
  2022-06-02 11:21 [PATCH] ax25: use GFP_KERNEL over GFP_ATOMIC where possible Peter Lafreniere
@ 2022-06-03  2:47 ` Jakub Kicinski
  2022-06-06 11:50 ` Dan Carpenter
  2022-06-06 11:54 ` Dan Carpenter
  2 siblings, 0 replies; 6+ messages in thread
From: Jakub Kicinski @ 2022-06-03  2:47 UTC (permalink / raw)
  To: Peter Lafreniere; +Cc: linux-hams, ralf, netdev

On Thu,  2 Jun 2022 07:21:38 -0400 Peter Lafreniere wrote:
> There are a few functions that can sleep that use GFP_ATOMIC.
> Here we change allocations to use the more reliable GFP_KERNEL
> flag.
> 
> ax25_dev_device_up() is only called during device setup, which is
> done in user context. In addition, ax25_dev_device_up()
> unconditionally calls ax25_register_dev_sysctl(), which already
> allocates with GFP_KERNEL.
> 
> ax25_rt_add() is a static function that is only called from
> ax25_rt_ioctl(), which must run in user context already due to
> copy_from_user() usage.
> 
> Since it is allowed to sleep in both of these functions, here we
> change the functions to use GFP_KERNEL to reduce unnecessary
> out-of-memory errors.
> 
> Signed-off-by: Peter Lafreniere <pjlafren@mtu.edu>

For merging into the Linux networking trees you'll have to repost next
week, this seems like an optimization and we're currently in the merge
window period where we only accept fixes.

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

* Re: [PATCH] ax25: use GFP_KERNEL over GFP_ATOMIC where possible
  2022-06-02 11:21 [PATCH] ax25: use GFP_KERNEL over GFP_ATOMIC where possible Peter Lafreniere
@ 2022-06-06 11:54 ` Dan Carpenter
  2022-06-06 11:50 ` Dan Carpenter
  2022-06-06 11:54 ` Dan Carpenter
  2 siblings, 0 replies; 6+ messages in thread
From: kernel test robot @ 2022-06-03  7:37 UTC (permalink / raw)
  To: kbuild

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

CC: kbuild-all(a)lists.01.org
BCC: lkp(a)intel.com
In-Reply-To: <20220602112138.8200-1-pjlafren@mtu.edu>
References: <20220602112138.8200-1-pjlafren@mtu.edu>
TO: Peter Lafreniere <pjlafren@mtu.edu>
TO: linux-hams(a)vger.kernel.org
CC: ralf(a)linux-mips.org
CC: netdev(a)vger.kernel.org
CC: Peter Lafreniere <pjlafren@mtu.edu>

Hi Peter,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on horms-ipvs/master]
[also build test WARNING on net/master net-next/master linus/master v5.18 next-20220603]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/intel-lab-lkp/linux/commits/Peter-Lafreniere/ax25-use-GFP_KERNEL-over-GFP_ATOMIC-where-possible/20220602-192326
base:   https://git.kernel.org/pub/scm/linux/kernel/git/horms/ipvs.git master
:::::: branch date: 20 hours ago
:::::: commit date: 20 hours ago
config: nios2-randconfig-m031-20220601 (https://download.01.org/0day-ci/archive/20220603/202206031536.t0bHoh3z-lkp(a)intel.com/config)
compiler: nios2-linux-gcc (GCC) 11.3.0

If you fix the issue, kindly add following tag where applicable
Reported-by: kernel test robot <lkp@intel.com>
Reported-by: Dan Carpenter <dan.carpenter@oracle.com>

New smatch warnings:
net/ax25/ax25_route.c:94 ax25_rt_add() warn: sleeping in atomic context

Old smatch warnings:
arch/nios2/include/asm/thread_info.h:62 current_thread_info() error: uninitialized symbol 'sp'.
net/ax25/ax25_route.c:113 ax25_rt_add() warn: sleeping in atomic context

vim +94 net/ax25/ax25_route.c

^1da177e4c3f415 Linus Torvalds   2005-04-16   71  
c9266b99e2def0a Ralf Baechle     2006-12-14   72  static int __must_check ax25_rt_add(struct ax25_routes_struct *route)
^1da177e4c3f415 Linus Torvalds   2005-04-16   73  {
^1da177e4c3f415 Linus Torvalds   2005-04-16   74  	ax25_route *ax25_rt;
^1da177e4c3f415 Linus Torvalds   2005-04-16   75  	ax25_dev *ax25_dev;
^1da177e4c3f415 Linus Torvalds   2005-04-16   76  	int i;
^1da177e4c3f415 Linus Torvalds   2005-04-16   77  
^1da177e4c3f415 Linus Torvalds   2005-04-16   78  	if (route->digi_count > AX25_MAX_DIGIS)
^1da177e4c3f415 Linus Torvalds   2005-04-16   79  		return -EINVAL;
^1da177e4c3f415 Linus Torvalds   2005-04-16   80  
87563a043cef044 Duoming Zhou     2022-02-03   81  	ax25_dev = ax25_addr_ax25dev(&route->port_addr);
87563a043cef044 Duoming Zhou     2022-02-03   82  	if (!ax25_dev)
87563a043cef044 Duoming Zhou     2022-02-03   83  		return -EINVAL;
87563a043cef044 Duoming Zhou     2022-02-03   84  
4de211f1a279275 Jarek Poplawski  2008-02-11   85  	write_lock_bh(&ax25_route_lock);
^1da177e4c3f415 Linus Torvalds   2005-04-16   86  
^1da177e4c3f415 Linus Torvalds   2005-04-16   87  	ax25_rt = ax25_route_list;
^1da177e4c3f415 Linus Torvalds   2005-04-16   88  	while (ax25_rt != NULL) {
^1da177e4c3f415 Linus Torvalds   2005-04-16   89  		if (ax25cmp(&ax25_rt->callsign, &route->dest_addr) == 0 &&
^1da177e4c3f415 Linus Torvalds   2005-04-16   90  			    ax25_rt->dev == ax25_dev->dev) {
^1da177e4c3f415 Linus Torvalds   2005-04-16   91  			kfree(ax25_rt->digipeat);
^1da177e4c3f415 Linus Torvalds   2005-04-16   92  			ax25_rt->digipeat = NULL;
^1da177e4c3f415 Linus Torvalds   2005-04-16   93  			if (route->digi_count != 0) {
10c95f710e8899b Peter Lafreniere 2022-06-02  @94  				if ((ax25_rt->digipeat = kmalloc(sizeof(ax25_digi), GFP_KERNEL)) == NULL) {
4de211f1a279275 Jarek Poplawski  2008-02-11   95  					write_unlock_bh(&ax25_route_lock);
87563a043cef044 Duoming Zhou     2022-02-03   96  					ax25_dev_put(ax25_dev);
^1da177e4c3f415 Linus Torvalds   2005-04-16   97  					return -ENOMEM;
^1da177e4c3f415 Linus Torvalds   2005-04-16   98  				}
^1da177e4c3f415 Linus Torvalds   2005-04-16   99  				ax25_rt->digipeat->lastrepeat = -1;
^1da177e4c3f415 Linus Torvalds   2005-04-16  100  				ax25_rt->digipeat->ndigi      = route->digi_count;
^1da177e4c3f415 Linus Torvalds   2005-04-16  101  				for (i = 0; i < route->digi_count; i++) {
^1da177e4c3f415 Linus Torvalds   2005-04-16  102  					ax25_rt->digipeat->repeated[i] = 0;
^1da177e4c3f415 Linus Torvalds   2005-04-16  103  					ax25_rt->digipeat->calls[i]    = route->digi_addr[i];
^1da177e4c3f415 Linus Torvalds   2005-04-16  104  				}
^1da177e4c3f415 Linus Torvalds   2005-04-16  105  			}
4de211f1a279275 Jarek Poplawski  2008-02-11  106  			write_unlock_bh(&ax25_route_lock);
87563a043cef044 Duoming Zhou     2022-02-03  107  			ax25_dev_put(ax25_dev);
^1da177e4c3f415 Linus Torvalds   2005-04-16  108  			return 0;
^1da177e4c3f415 Linus Torvalds   2005-04-16  109  		}
^1da177e4c3f415 Linus Torvalds   2005-04-16  110  		ax25_rt = ax25_rt->next;
^1da177e4c3f415 Linus Torvalds   2005-04-16  111  	}
^1da177e4c3f415 Linus Torvalds   2005-04-16  112  
10c95f710e8899b Peter Lafreniere 2022-06-02  113  	if ((ax25_rt = kmalloc(sizeof(ax25_route), GFP_KERNEL)) == NULL) {
4de211f1a279275 Jarek Poplawski  2008-02-11  114  		write_unlock_bh(&ax25_route_lock);
87563a043cef044 Duoming Zhou     2022-02-03  115  		ax25_dev_put(ax25_dev);
^1da177e4c3f415 Linus Torvalds   2005-04-16  116  		return -ENOMEM;
^1da177e4c3f415 Linus Torvalds   2005-04-16  117  	}
^1da177e4c3f415 Linus Torvalds   2005-04-16  118  
^1da177e4c3f415 Linus Torvalds   2005-04-16  119  	ax25_rt->callsign     = route->dest_addr;
^1da177e4c3f415 Linus Torvalds   2005-04-16  120  	ax25_rt->dev          = ax25_dev->dev;
^1da177e4c3f415 Linus Torvalds   2005-04-16  121  	ax25_rt->digipeat     = NULL;
^1da177e4c3f415 Linus Torvalds   2005-04-16  122  	ax25_rt->ip_mode      = ' ';
^1da177e4c3f415 Linus Torvalds   2005-04-16  123  	if (route->digi_count != 0) {
^1da177e4c3f415 Linus Torvalds   2005-04-16  124  		if ((ax25_rt->digipeat = kmalloc(sizeof(ax25_digi), GFP_ATOMIC)) == NULL) {
4de211f1a279275 Jarek Poplawski  2008-02-11  125  			write_unlock_bh(&ax25_route_lock);
^1da177e4c3f415 Linus Torvalds   2005-04-16  126  			kfree(ax25_rt);
87563a043cef044 Duoming Zhou     2022-02-03  127  			ax25_dev_put(ax25_dev);
^1da177e4c3f415 Linus Torvalds   2005-04-16  128  			return -ENOMEM;
^1da177e4c3f415 Linus Torvalds   2005-04-16  129  		}
^1da177e4c3f415 Linus Torvalds   2005-04-16  130  		ax25_rt->digipeat->lastrepeat = -1;
^1da177e4c3f415 Linus Torvalds   2005-04-16  131  		ax25_rt->digipeat->ndigi      = route->digi_count;
^1da177e4c3f415 Linus Torvalds   2005-04-16  132  		for (i = 0; i < route->digi_count; i++) {
^1da177e4c3f415 Linus Torvalds   2005-04-16  133  			ax25_rt->digipeat->repeated[i] = 0;
^1da177e4c3f415 Linus Torvalds   2005-04-16  134  			ax25_rt->digipeat->calls[i]    = route->digi_addr[i];
^1da177e4c3f415 Linus Torvalds   2005-04-16  135  		}
^1da177e4c3f415 Linus Torvalds   2005-04-16  136  	}
^1da177e4c3f415 Linus Torvalds   2005-04-16  137  	ax25_rt->next   = ax25_route_list;
^1da177e4c3f415 Linus Torvalds   2005-04-16  138  	ax25_route_list = ax25_rt;
4de211f1a279275 Jarek Poplawski  2008-02-11  139  	write_unlock_bh(&ax25_route_lock);
87563a043cef044 Duoming Zhou     2022-02-03  140  	ax25_dev_put(ax25_dev);
^1da177e4c3f415 Linus Torvalds   2005-04-16  141  
^1da177e4c3f415 Linus Torvalds   2005-04-16  142  	return 0;
^1da177e4c3f415 Linus Torvalds   2005-04-16  143  }
^1da177e4c3f415 Linus Torvalds   2005-04-16  144  

-- 
0-DAY CI Kernel Test Service
https://01.org/lkp

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

* Re: [PATCH] ax25: use GFP_KERNEL over GFP_ATOMIC where possible
  2022-06-02 11:21 [PATCH] ax25: use GFP_KERNEL over GFP_ATOMIC where possible Peter Lafreniere
  2022-06-03  2:47 ` Jakub Kicinski
@ 2022-06-06 11:50 ` Dan Carpenter
  2022-06-06 11:54 ` Dan Carpenter
  2 siblings, 0 replies; 6+ messages in thread
From: Dan Carpenter @ 2022-06-06 11:50 UTC (permalink / raw)
  To: Peter Lafreniere; +Cc: linux-hams, ralf, netdev

On Thu, Jun 02, 2022 at 07:21:38AM -0400, Peter Lafreniere wrote:
>  net/ax25/ax25_dev.c   | 4 ++--
>  net/ax25/ax25_route.c | 4 ++--
>  2 files changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/net/ax25/ax25_dev.c b/net/ax25/ax25_dev.c
> index d2a244e1c260..b264904980a8 100644
> --- a/net/ax25/ax25_dev.c
> +++ b/net/ax25/ax25_dev.c
> @@ -52,7 +52,7 @@ void ax25_dev_device_up(struct net_device *dev)
>  {
>  	ax25_dev *ax25_dev;
>  
> -	if ((ax25_dev = kzalloc(sizeof(*ax25_dev), GFP_ATOMIC)) == NULL) {
> +	if ((ax25_dev = kzalloc(sizeof(*ax25_dev), GFP_KERNEL)) == NULL) {
>  		printk(KERN_ERR "AX.25: ax25_dev_device_up - out of memory\n");
>  		return;
>  	}
> @@ -60,7 +60,7 @@ void ax25_dev_device_up(struct net_device *dev)
>  	refcount_set(&ax25_dev->refcount, 1);
>  	dev->ax25_ptr     = ax25_dev;
>  	ax25_dev->dev     = dev;
> -	dev_hold_track(dev, &ax25_dev->dev_tracker, GFP_ATOMIC);
> +	dev_hold_track(dev, &ax25_dev->dev_tracker, GFP_KERNEL);
>  	ax25_dev->forward = NULL;
>  
>  	ax25_dev->values[AX25_VALUES_IPDEFMODE] = AX25_DEF_IPDEFMODE;

These two are fine.

> diff --git a/net/ax25/ax25_route.c b/net/ax25/ax25_route.c
> index b7c4d656a94b..c77b848ccfc7 100644
> --- a/net/ax25/ax25_route.c
> +++ b/net/ax25/ax25_route.c
> @@ -91,7 +91,7 @@ static int __must_check ax25_rt_add(struct ax25_routes_struct *route)
>  			kfree(ax25_rt->digipeat);
>  			ax25_rt->digipeat = NULL;
>  			if (route->digi_count != 0) {
> -				if ((ax25_rt->digipeat = kmalloc(sizeof(ax25_digi), GFP_ATOMIC)) == NULL) {
> +				if ((ax25_rt->digipeat = kmalloc(sizeof(ax25_digi), GFP_KERNEL)) == NULL) {
>  					write_unlock_bh(&ax25_route_lock);

This write lock means it has to be GFP_ATOMIC.

>  					ax25_dev_put(ax25_dev);
>  					return -ENOMEM;
> @@ -110,7 +110,7 @@ static int __must_check ax25_rt_add(struct ax25_routes_struct *route)
>  		ax25_rt = ax25_rt->next;
>  	}
>  
> -	if ((ax25_rt = kmalloc(sizeof(ax25_route), GFP_ATOMIC)) == NULL) {
> +	if ((ax25_rt = kmalloc(sizeof(ax25_route), GFP_KERNEL)) == NULL) {
>  		write_unlock_bh(&ax25_route_lock);

This change is buggy as well.

>  		ax25_dev_put(ax25_dev);
>  		return -ENOMEM;

regards,
dan carpenter

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

* Re: [PATCH] ax25: use GFP_KERNEL over GFP_ATOMIC where possible
@ 2022-06-06 11:54 ` Dan Carpenter
  0 siblings, 0 replies; 6+ messages in thread
From: Dan Carpenter @ 2022-06-06 11:54 UTC (permalink / raw)
  To: kbuild-all

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

[ Kbuild catches the bug as well - dan.  netdev trimmed from the CC list. ]

Hi Peter,

url:    https://github.com/intel-lab-lkp/linux/commits/Peter-Lafreniere/ax25-use-GFP_KERNEL-over-GFP_ATOMIC-where-possible/20220602-192326
base:   https://git.kernel.org/pub/scm/linux/kernel/git/horms/ipvs.git master
config: nios2-randconfig-m031-20220601 (https://download.01.org/0day-ci/archive/20220603/202206031536.t0bHoh3z-lkp(a)intel.com/config)
compiler: nios2-linux-gcc (GCC) 11.3.0

If you fix the issue, kindly add following tag where applicable
Reported-by: kernel test robot <lkp@intel.com>
Reported-by: Dan Carpenter <dan.carpenter@oracle.com>

New smatch warnings:
net/ax25/ax25_route.c:94 ax25_rt_add() warn: sleeping in atomic context

Old smatch warnings:
net/ax25/ax25_route.c:113 ax25_rt_add() warn: sleeping in atomic context

vim +94 net/ax25/ax25_route.c

c9266b99e2def0a Ralf Baechle     2006-12-14   72  static int __must_check ax25_rt_add(struct ax25_routes_struct *route)
^1da177e4c3f415 Linus Torvalds   2005-04-16   73  {
^1da177e4c3f415 Linus Torvalds   2005-04-16   74  	ax25_route *ax25_rt;
^1da177e4c3f415 Linus Torvalds   2005-04-16   75  	ax25_dev *ax25_dev;
^1da177e4c3f415 Linus Torvalds   2005-04-16   76  	int i;
^1da177e4c3f415 Linus Torvalds   2005-04-16   77  
^1da177e4c3f415 Linus Torvalds   2005-04-16   78  	if (route->digi_count > AX25_MAX_DIGIS)
^1da177e4c3f415 Linus Torvalds   2005-04-16   79  		return -EINVAL;
^1da177e4c3f415 Linus Torvalds   2005-04-16   80  
87563a043cef044 Duoming Zhou     2022-02-03   81  	ax25_dev = ax25_addr_ax25dev(&route->port_addr);
87563a043cef044 Duoming Zhou     2022-02-03   82  	if (!ax25_dev)
87563a043cef044 Duoming Zhou     2022-02-03   83  		return -EINVAL;
87563a043cef044 Duoming Zhou     2022-02-03   84  
4de211f1a279275 Jarek Poplawski  2008-02-11   85  	write_lock_bh(&ax25_route_lock);
^1da177e4c3f415 Linus Torvalds   2005-04-16   86  
^1da177e4c3f415 Linus Torvalds   2005-04-16   87  	ax25_rt = ax25_route_list;
^1da177e4c3f415 Linus Torvalds   2005-04-16   88  	while (ax25_rt != NULL) {
^1da177e4c3f415 Linus Torvalds   2005-04-16   89  		if (ax25cmp(&ax25_rt->callsign, &route->dest_addr) == 0 &&
^1da177e4c3f415 Linus Torvalds   2005-04-16   90  			    ax25_rt->dev == ax25_dev->dev) {
^1da177e4c3f415 Linus Torvalds   2005-04-16   91  			kfree(ax25_rt->digipeat);
^1da177e4c3f415 Linus Torvalds   2005-04-16   92  			ax25_rt->digipeat = NULL;
^1da177e4c3f415 Linus Torvalds   2005-04-16   93  			if (route->digi_count != 0) {
10c95f710e8899b Peter Lafreniere 2022-06-02  @94  				if ((ax25_rt->digipeat = kmalloc(sizeof(ax25_digi), GFP_KERNEL)) == NULL) {
4de211f1a279275 Jarek Poplawski  2008-02-11   95  					write_unlock_bh(&ax25_route_lock);
87563a043cef044 Duoming Zhou     2022-02-03   96  					ax25_dev_put(ax25_dev);
^1da177e4c3f415 Linus Torvalds   2005-04-16   97  					return -ENOMEM;
^1da177e4c3f415 Linus Torvalds   2005-04-16   98  				}
^1da177e4c3f415 Linus Torvalds   2005-04-16   99  				ax25_rt->digipeat->lastrepeat = -1;
^1da177e4c3f415 Linus Torvalds   2005-04-16  100  				ax25_rt->digipeat->ndigi      = route->digi_count;
^1da177e4c3f415 Linus Torvalds   2005-04-16  101  				for (i = 0; i < route->digi_count; i++) {
^1da177e4c3f415 Linus Torvalds   2005-04-16  102  					ax25_rt->digipeat->repeated[i] = 0;
^1da177e4c3f415 Linus Torvalds   2005-04-16  103  					ax25_rt->digipeat->calls[i]    = route->digi_addr[i];
^1da177e4c3f415 Linus Torvalds   2005-04-16  104  				}
^1da177e4c3f415 Linus Torvalds   2005-04-16  105  			}
4de211f1a279275 Jarek Poplawski  2008-02-11  106  			write_unlock_bh(&ax25_route_lock);
87563a043cef044 Duoming Zhou     2022-02-03  107  			ax25_dev_put(ax25_dev);
^1da177e4c3f415 Linus Torvalds   2005-04-16  108  			return 0;
^1da177e4c3f415 Linus Torvalds   2005-04-16  109  		}
^1da177e4c3f415 Linus Torvalds   2005-04-16  110  		ax25_rt = ax25_rt->next;
^1da177e4c3f415 Linus Torvalds   2005-04-16  111  	}
^1da177e4c3f415 Linus Torvalds   2005-04-16  112  
10c95f710e8899b Peter Lafreniere 2022-06-02  113  	if ((ax25_rt = kmalloc(sizeof(ax25_route), GFP_KERNEL)) == NULL) {
4de211f1a279275 Jarek Poplawski  2008-02-11  114  		write_unlock_bh(&ax25_route_lock);
87563a043cef044 Duoming Zhou     2022-02-03  115  		ax25_dev_put(ax25_dev);
^1da177e4c3f415 Linus Torvalds   2005-04-16  116  		return -ENOMEM;
^1da177e4c3f415 Linus Torvalds   2005-04-16  117  	}
^1da177e4c3f415 Linus Torvalds   2005-04-16  118  
^1da177e4c3f415 Linus Torvalds   2005-04-16  119  	ax25_rt->callsign     = route->dest_addr;
^1da177e4c3f415 Linus Torvalds   2005-04-16  120  	ax25_rt->dev          = ax25_dev->dev;
^1da177e4c3f415 Linus Torvalds   2005-04-16  121  	ax25_rt->digipeat     = NULL;
^1da177e4c3f415 Linus Torvalds   2005-04-16  122  	ax25_rt->ip_mode      = ' ';
^1da177e4c3f415 Linus Torvalds   2005-04-16  123  	if (route->digi_count != 0) {
^1da177e4c3f415 Linus Torvalds   2005-04-16  124  		if ((ax25_rt->digipeat = kmalloc(sizeof(ax25_digi), GFP_ATOMIC)) == NULL) {
4de211f1a279275 Jarek Poplawski  2008-02-11  125  			write_unlock_bh(&ax25_route_lock);
^1da177e4c3f415 Linus Torvalds   2005-04-16  126  			kfree(ax25_rt);
87563a043cef044 Duoming Zhou     2022-02-03  127  			ax25_dev_put(ax25_dev);
^1da177e4c3f415 Linus Torvalds   2005-04-16  128  			return -ENOMEM;
^1da177e4c3f415 Linus Torvalds   2005-04-16  129  		}
^1da177e4c3f415 Linus Torvalds   2005-04-16  130  		ax25_rt->digipeat->lastrepeat = -1;
^1da177e4c3f415 Linus Torvalds   2005-04-16  131  		ax25_rt->digipeat->ndigi      = route->digi_count;
^1da177e4c3f415 Linus Torvalds   2005-04-16  132  		for (i = 0; i < route->digi_count; i++) {
^1da177e4c3f415 Linus Torvalds   2005-04-16  133  			ax25_rt->digipeat->repeated[i] = 0;
^1da177e4c3f415 Linus Torvalds   2005-04-16  134  			ax25_rt->digipeat->calls[i]    = route->digi_addr[i];
^1da177e4c3f415 Linus Torvalds   2005-04-16  135  		}
^1da177e4c3f415 Linus Torvalds   2005-04-16  136  	}
^1da177e4c3f415 Linus Torvalds   2005-04-16  137  	ax25_rt->next   = ax25_route_list;
^1da177e4c3f415 Linus Torvalds   2005-04-16  138  	ax25_route_list = ax25_rt;
4de211f1a279275 Jarek Poplawski  2008-02-11  139  	write_unlock_bh(&ax25_route_lock);
87563a043cef044 Duoming Zhou     2022-02-03  140  	ax25_dev_put(ax25_dev);
^1da177e4c3f415 Linus Torvalds   2005-04-16  141  
^1da177e4c3f415 Linus Torvalds   2005-04-16  142  	return 0;
^1da177e4c3f415 Linus Torvalds   2005-04-16  143  }

-- 
0-DAY CI Kernel Test Service
https://01.org/lkp

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

* Re: [PATCH] ax25: use GFP_KERNEL over GFP_ATOMIC where possible
  2022-06-02 11:21 [PATCH] ax25: use GFP_KERNEL over GFP_ATOMIC where possible Peter Lafreniere
  2022-06-03  2:47 ` Jakub Kicinski
  2022-06-06 11:50 ` Dan Carpenter
@ 2022-06-06 11:54 ` Dan Carpenter
  2 siblings, 0 replies; 6+ messages in thread
From: Dan Carpenter @ 2022-06-06 11:54 UTC (permalink / raw)
  To: kbuild, Peter Lafreniere, linux-hams
  Cc: lkp, kbuild-all, ralf, Peter Lafreniere

[ Kbuild catches the bug as well - dan.  netdev trimmed from the CC list. ]

Hi Peter,

url:    https://github.com/intel-lab-lkp/linux/commits/Peter-Lafreniere/ax25-use-GFP_KERNEL-over-GFP_ATOMIC-where-possible/20220602-192326
base:   https://git.kernel.org/pub/scm/linux/kernel/git/horms/ipvs.git master
config: nios2-randconfig-m031-20220601 (https://download.01.org/0day-ci/archive/20220603/202206031536.t0bHoh3z-lkp@intel.com/config)
compiler: nios2-linux-gcc (GCC) 11.3.0

If you fix the issue, kindly add following tag where applicable
Reported-by: kernel test robot <lkp@intel.com>
Reported-by: Dan Carpenter <dan.carpenter@oracle.com>

New smatch warnings:
net/ax25/ax25_route.c:94 ax25_rt_add() warn: sleeping in atomic context

Old smatch warnings:
net/ax25/ax25_route.c:113 ax25_rt_add() warn: sleeping in atomic context

vim +94 net/ax25/ax25_route.c

c9266b99e2def0a Ralf Baechle     2006-12-14   72  static int __must_check ax25_rt_add(struct ax25_routes_struct *route)
^1da177e4c3f415 Linus Torvalds   2005-04-16   73  {
^1da177e4c3f415 Linus Torvalds   2005-04-16   74  	ax25_route *ax25_rt;
^1da177e4c3f415 Linus Torvalds   2005-04-16   75  	ax25_dev *ax25_dev;
^1da177e4c3f415 Linus Torvalds   2005-04-16   76  	int i;
^1da177e4c3f415 Linus Torvalds   2005-04-16   77  
^1da177e4c3f415 Linus Torvalds   2005-04-16   78  	if (route->digi_count > AX25_MAX_DIGIS)
^1da177e4c3f415 Linus Torvalds   2005-04-16   79  		return -EINVAL;
^1da177e4c3f415 Linus Torvalds   2005-04-16   80  
87563a043cef044 Duoming Zhou     2022-02-03   81  	ax25_dev = ax25_addr_ax25dev(&route->port_addr);
87563a043cef044 Duoming Zhou     2022-02-03   82  	if (!ax25_dev)
87563a043cef044 Duoming Zhou     2022-02-03   83  		return -EINVAL;
87563a043cef044 Duoming Zhou     2022-02-03   84  
4de211f1a279275 Jarek Poplawski  2008-02-11   85  	write_lock_bh(&ax25_route_lock);
^1da177e4c3f415 Linus Torvalds   2005-04-16   86  
^1da177e4c3f415 Linus Torvalds   2005-04-16   87  	ax25_rt = ax25_route_list;
^1da177e4c3f415 Linus Torvalds   2005-04-16   88  	while (ax25_rt != NULL) {
^1da177e4c3f415 Linus Torvalds   2005-04-16   89  		if (ax25cmp(&ax25_rt->callsign, &route->dest_addr) == 0 &&
^1da177e4c3f415 Linus Torvalds   2005-04-16   90  			    ax25_rt->dev == ax25_dev->dev) {
^1da177e4c3f415 Linus Torvalds   2005-04-16   91  			kfree(ax25_rt->digipeat);
^1da177e4c3f415 Linus Torvalds   2005-04-16   92  			ax25_rt->digipeat = NULL;
^1da177e4c3f415 Linus Torvalds   2005-04-16   93  			if (route->digi_count != 0) {
10c95f710e8899b Peter Lafreniere 2022-06-02  @94  				if ((ax25_rt->digipeat = kmalloc(sizeof(ax25_digi), GFP_KERNEL)) == NULL) {
4de211f1a279275 Jarek Poplawski  2008-02-11   95  					write_unlock_bh(&ax25_route_lock);
87563a043cef044 Duoming Zhou     2022-02-03   96  					ax25_dev_put(ax25_dev);
^1da177e4c3f415 Linus Torvalds   2005-04-16   97  					return -ENOMEM;
^1da177e4c3f415 Linus Torvalds   2005-04-16   98  				}
^1da177e4c3f415 Linus Torvalds   2005-04-16   99  				ax25_rt->digipeat->lastrepeat = -1;
^1da177e4c3f415 Linus Torvalds   2005-04-16  100  				ax25_rt->digipeat->ndigi      = route->digi_count;
^1da177e4c3f415 Linus Torvalds   2005-04-16  101  				for (i = 0; i < route->digi_count; i++) {
^1da177e4c3f415 Linus Torvalds   2005-04-16  102  					ax25_rt->digipeat->repeated[i] = 0;
^1da177e4c3f415 Linus Torvalds   2005-04-16  103  					ax25_rt->digipeat->calls[i]    = route->digi_addr[i];
^1da177e4c3f415 Linus Torvalds   2005-04-16  104  				}
^1da177e4c3f415 Linus Torvalds   2005-04-16  105  			}
4de211f1a279275 Jarek Poplawski  2008-02-11  106  			write_unlock_bh(&ax25_route_lock);
87563a043cef044 Duoming Zhou     2022-02-03  107  			ax25_dev_put(ax25_dev);
^1da177e4c3f415 Linus Torvalds   2005-04-16  108  			return 0;
^1da177e4c3f415 Linus Torvalds   2005-04-16  109  		}
^1da177e4c3f415 Linus Torvalds   2005-04-16  110  		ax25_rt = ax25_rt->next;
^1da177e4c3f415 Linus Torvalds   2005-04-16  111  	}
^1da177e4c3f415 Linus Torvalds   2005-04-16  112  
10c95f710e8899b Peter Lafreniere 2022-06-02  113  	if ((ax25_rt = kmalloc(sizeof(ax25_route), GFP_KERNEL)) == NULL) {
4de211f1a279275 Jarek Poplawski  2008-02-11  114  		write_unlock_bh(&ax25_route_lock);
87563a043cef044 Duoming Zhou     2022-02-03  115  		ax25_dev_put(ax25_dev);
^1da177e4c3f415 Linus Torvalds   2005-04-16  116  		return -ENOMEM;
^1da177e4c3f415 Linus Torvalds   2005-04-16  117  	}
^1da177e4c3f415 Linus Torvalds   2005-04-16  118  
^1da177e4c3f415 Linus Torvalds   2005-04-16  119  	ax25_rt->callsign     = route->dest_addr;
^1da177e4c3f415 Linus Torvalds   2005-04-16  120  	ax25_rt->dev          = ax25_dev->dev;
^1da177e4c3f415 Linus Torvalds   2005-04-16  121  	ax25_rt->digipeat     = NULL;
^1da177e4c3f415 Linus Torvalds   2005-04-16  122  	ax25_rt->ip_mode      = ' ';
^1da177e4c3f415 Linus Torvalds   2005-04-16  123  	if (route->digi_count != 0) {
^1da177e4c3f415 Linus Torvalds   2005-04-16  124  		if ((ax25_rt->digipeat = kmalloc(sizeof(ax25_digi), GFP_ATOMIC)) == NULL) {
4de211f1a279275 Jarek Poplawski  2008-02-11  125  			write_unlock_bh(&ax25_route_lock);
^1da177e4c3f415 Linus Torvalds   2005-04-16  126  			kfree(ax25_rt);
87563a043cef044 Duoming Zhou     2022-02-03  127  			ax25_dev_put(ax25_dev);
^1da177e4c3f415 Linus Torvalds   2005-04-16  128  			return -ENOMEM;
^1da177e4c3f415 Linus Torvalds   2005-04-16  129  		}
^1da177e4c3f415 Linus Torvalds   2005-04-16  130  		ax25_rt->digipeat->lastrepeat = -1;
^1da177e4c3f415 Linus Torvalds   2005-04-16  131  		ax25_rt->digipeat->ndigi      = route->digi_count;
^1da177e4c3f415 Linus Torvalds   2005-04-16  132  		for (i = 0; i < route->digi_count; i++) {
^1da177e4c3f415 Linus Torvalds   2005-04-16  133  			ax25_rt->digipeat->repeated[i] = 0;
^1da177e4c3f415 Linus Torvalds   2005-04-16  134  			ax25_rt->digipeat->calls[i]    = route->digi_addr[i];
^1da177e4c3f415 Linus Torvalds   2005-04-16  135  		}
^1da177e4c3f415 Linus Torvalds   2005-04-16  136  	}
^1da177e4c3f415 Linus Torvalds   2005-04-16  137  	ax25_rt->next   = ax25_route_list;
^1da177e4c3f415 Linus Torvalds   2005-04-16  138  	ax25_route_list = ax25_rt;
4de211f1a279275 Jarek Poplawski  2008-02-11  139  	write_unlock_bh(&ax25_route_lock);
87563a043cef044 Duoming Zhou     2022-02-03  140  	ax25_dev_put(ax25_dev);
^1da177e4c3f415 Linus Torvalds   2005-04-16  141  
^1da177e4c3f415 Linus Torvalds   2005-04-16  142  	return 0;
^1da177e4c3f415 Linus Torvalds   2005-04-16  143  }

-- 
0-DAY CI Kernel Test Service
https://01.org/lkp


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

end of thread, other threads:[~2022-06-06 11:54 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-02 11:21 [PATCH] ax25: use GFP_KERNEL over GFP_ATOMIC where possible Peter Lafreniere
2022-06-03  2:47 ` Jakub Kicinski
2022-06-06 11:50 ` Dan Carpenter
2022-06-06 11:54 ` Dan Carpenter
2022-06-03  7:37 kernel test robot
2022-06-06 11:54 ` Dan Carpenter

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.