mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] staging: gasket: sysfs: fix potential null dereference
@ 2018-07-31 15:23 Ivan Bornyakov
  2018-08-01 18:08 ` Greg KH
  0 siblings, 1 reply; 3+ messages in thread
From: Ivan Bornyakov @ 2018-07-31 15:23 UTC (permalink / raw)
  To: devel; +Cc: linux-kernel, gregkh, benchan, jnjoseph, rspringer, Ivan Bornyakov

Add handling of possible allocation failure.

Reported by smatch:

  drivers/staging/gasket/gasket_sysfs.c:105 put_mapping() error: potential null dereference 'files_to_remove'. (kcalloc returns null)

Signed-off-by: Ivan Bornyakov <brnkv.i1@gmail.com>
---
 drivers/staging/gasket/gasket_sysfs.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/drivers/staging/gasket/gasket_sysfs.c b/drivers/staging/gasket/gasket_sysfs.c
index ef4eca02afa6..682e5c21f203 100644
--- a/drivers/staging/gasket/gasket_sysfs.c
+++ b/drivers/staging/gasket/gasket_sysfs.c
@@ -101,6 +101,12 @@ static void put_mapping(struct gasket_sysfs_mapping *mapping)
 		files_to_remove = kcalloc(num_files_to_remove,
 					  sizeof(*files_to_remove),
 					  GFP_KERNEL);
+		if (!files_to_remove) {
+			pr_err("%s: can't allocate memory\n", __func__);
+			mutex_unlock(&mapping->mutex);
+			return;
+		}
+
 		for (i = 0; i < num_files_to_remove; i++)
 			files_to_remove[i] = mapping->attributes[i].attr;
 
-- 
2.16.4


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

* Re: [PATCH] staging: gasket: sysfs: fix potential null dereference
  2018-07-31 15:23 [PATCH] staging: gasket: sysfs: fix potential null dereference Ivan Bornyakov
@ 2018-08-01 18:08 ` Greg KH
  2018-08-01 18:37   ` [PATCH v2] " Ivan Bornyakov
  0 siblings, 1 reply; 3+ messages in thread
From: Greg KH @ 2018-08-01 18:08 UTC (permalink / raw)
  To: Ivan Bornyakov; +Cc: devel, linux-kernel, benchan, jnjoseph, rspringer

On Tue, Jul 31, 2018 at 06:23:20PM +0300, Ivan Bornyakov wrote:
> Add handling of possible allocation failure.
> 
> Reported by smatch:
> 
>   drivers/staging/gasket/gasket_sysfs.c:105 put_mapping() error: potential null dereference 'files_to_remove'. (kcalloc returns null)
> 
> Signed-off-by: Ivan Bornyakov <brnkv.i1@gmail.com>
> ---
>  drivers/staging/gasket/gasket_sysfs.c | 6 ++++++
>  1 file changed, 6 insertions(+)
> 
> diff --git a/drivers/staging/gasket/gasket_sysfs.c b/drivers/staging/gasket/gasket_sysfs.c
> index ef4eca02afa6..682e5c21f203 100644
> --- a/drivers/staging/gasket/gasket_sysfs.c
> +++ b/drivers/staging/gasket/gasket_sysfs.c
> @@ -101,6 +101,12 @@ static void put_mapping(struct gasket_sysfs_mapping *mapping)
>  		files_to_remove = kcalloc(num_files_to_remove,
>  					  sizeof(*files_to_remove),
>  					  GFP_KERNEL);
> +		if (!files_to_remove) {
> +			pr_err("%s: can't allocate memory\n", __func__);

kcalloc failing will print something, no need to do it again here.

thanks,

greg k-h

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

* [PATCH v2] staging: gasket: sysfs: fix potential null dereference
  2018-08-01 18:08 ` Greg KH
@ 2018-08-01 18:37   ` Ivan Bornyakov
  0 siblings, 0 replies; 3+ messages in thread
From: Ivan Bornyakov @ 2018-08-01 18:37 UTC (permalink / raw)
  To: devel; +Cc: linux-kernel, gregkh, benchan, jnjoseph, rspringer, Ivan Bornyakov

Add handling of possible allocation failure.

Reported by smatch:

  drivers/staging/gasket/gasket_sysfs.c:105 put_mapping() error: potential null dereference 'files_to_remove'. (kcalloc returns null)

Signed-off-by: Ivan Bornyakov <brnkv.i1@gmail.com>
---
 drivers/staging/gasket/gasket_sysfs.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/drivers/staging/gasket/gasket_sysfs.c b/drivers/staging/gasket/gasket_sysfs.c
index a4bfca43cd03..56d62aea5111 100644
--- a/drivers/staging/gasket/gasket_sysfs.c
+++ b/drivers/staging/gasket/gasket_sysfs.c
@@ -101,6 +101,11 @@ static void put_mapping(struct gasket_sysfs_mapping *mapping)
 		files_to_remove = kcalloc(num_files_to_remove,
 					  sizeof(*files_to_remove),
 					  GFP_KERNEL);
+		if (!files_to_remove) {
+			mutex_unlock(&mapping->mutex);
+			return;
+		}
+
 		for (i = 0; i < num_files_to_remove; i++)
 			files_to_remove[i] = mapping->attributes[i].attr;
 
-- 
2.16.4


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

end of thread, other threads:[~2018-08-01 18:38 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-07-31 15:23 [PATCH] staging: gasket: sysfs: fix potential null dereference Ivan Bornyakov
2018-08-01 18:08 ` Greg KH
2018-08-01 18:37   ` [PATCH v2] " Ivan Bornyakov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®