Skip to contentSkip to conversation

media: nuvoton: npcm-video: Fix sleeping in atomic context

PATCH Superseded Marvin Lin 2 participants 3 messages Oct 3, 2023 – Oct 10, 2023

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Marvin Lin

author
#0 lore raw

PATCH 1/1 media: nuvoton: npcm-video: Fix sleeping in atomic context

Fix sleeping in atomic context warnings reported by the Smatch static analysis tool. Use GFP_ATOMIC instead of GFP_KERNEL in atomic context.

Fixes 70721089985c ("media: nuvoton: Add driver for NPCM video capture and encoding engine")
---
 drivers/media/platform/nuvoton/npcm-video.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/media/platform/nuvoton/npcm-video.c +2 -2
index ac8d73b794d3..5d160978f7b3 100644
@@ -412,7 +412,7 @@ static unsigned int npcm_video_add_rect(struct npcm_video *video,
 	struct rect_list *list = NULL;
 	struct v4l2_rect *r;
 
-	list = kzalloc(sizeof(*list), GFP_KERNEL);
+	list = kzalloc(sizeof(*list), GFP_ATOMIC);
 	if (!list)
 		return 0;
 
@@ -467,7 +467,7 @@ static struct rect_list *npcm_video_new_rect(struct npcm_video *video,
 	struct rect_list *list = NULL;
 	struct v4l2_rect *r;
 
-	list = kzalloc(sizeof(*list), GFP_KERNEL);
+	list = kzalloc(sizeof(*list), GFP_ATOMIC);
 	if (!list)
 		return NULL;
 
Signature · 1 line
2.34.1
#1 lore raw
Quoted 24 lines · Marvin Lin

Fix sleeping in atomic context warnings reported by the Smatch static analysis tool. Use GFP_ATOMIC instead of GFP_KERNEL in atomic context.

Fixes 70721089985c ("media: nuvoton: Add driver for NPCM video capture and encoding engine")
---
 drivers/media/platform/nuvoton/npcm-video.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/media/platform/nuvoton/npcm-video.c +1 -1
index ac8d73b794d3..5d160978f7b3 100644
@@ -412,7 +412,7 @@ static unsigned int npcm_video_add_rect(struct npcm_video *video,
 	struct rect_list *list = NULL;
 	struct v4l2_rect *r;
 
-	list = kzalloc(sizeof(*list), GFP_KERNEL);
+	list = kzalloc(sizeof(*list), GFP_ATOMIC);
 	if (!list)
 		return 0;
 

drivers/media/platform/nuvoton/npcm-video.c static struct rect_list *npcm_video_new_rect(struct npcm_video *video, · line 473

Quoted 8 lines
drivers/media/platform/nuvoton/npcm-video.c +1 -1
@@ -467,7 +467,7 @@ static struct rect_list *npcm_video_new_rect(struct npcm_video *video,
 	struct rect_list *list = NULL;
 	struct v4l2_rect *r;
 
-	list = kzalloc(sizeof(*list), GFP_KERNEL);
+	list = kzalloc(sizeof(*list), GFP_ATOMIC);
 	if (!list)
 		return NULL;
 

I'm not really sure this is the right approach.

Looking closer at the code I notice that npcm_video_irq is a threaded interrupt handler, so wouldn't it be easier to change the video->lock spinlock to a mutex?

Regards,

Hans

author
#2 lore raw

Hi Hans,

Thanks for the review.

Quoted 6 lines

drivers/media/platform/nuvoton/npcm-video.c static struct rect_list *npcm_video_new_rect(struct npcm_video *video, · line 472

Quoted 5 lines
drivers/media/platform/nuvoton/npcm-video.c +1 -1
-     list = kzalloc(sizeof(*list), GFP_KERNEL);
+     list = kzalloc(sizeof(*list), GFP_ATOMIC);
      if (!list)
              return NULL;
Quoted 6 lines

I'm not really sure this is the right approach.

Looking closer at the code I notice that npcm_video_irq is a threaded interrupt handler, so wouldn't it be easier to change the video->lock spinlock to a mutex?

Agree it's better to use mutex. Will send v2 for this.

Regards,
Marvin