Skip to contentSkip to conversation

staging: wlang-ng: get memory from kernel allocators instead of big static buffer

PATCH In review Sergio Paracuellos 2 participants 7 messages Oct 3, 2016 – Oct 9, 2016 Staging

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 staging: wlang-ng: get memory from kernel allocators instead of big static buffer

This patch fix the following sparse warnings in prism2fw.c:
warning: memset with byte count of 120000

---
 drivers/staging/wlan-ng/prism2fw.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)
drivers/staging/wlan-ng/prism2fw.c +8 -3
index 96aa211..7e33048 100644
@@ -124,7 +124,7 @@ struct imgchunk {
 
 /* Data records */
 static unsigned int ns3data;
-static struct s3datarec s3data[S3DATA_MAX];
+static struct s3datarec *s3data;
 
 /* Plug records */
 static unsigned int ns3plug;
@@ -248,7 +248,12 @@ static int prism2_fwapply(const struct ihex_binrec *rfptr,
 
 	/* Initialize the data structures */
 	ns3data = 0;
-	memset(s3data, 0, sizeof(s3data));
+	s3data = kcalloc(S3DATA_MAX, sizeof(*s3data), GFP_KERNEL);
+	if (unlikely(!s3data)) {
+		result = -ENOMEM;
+		goto out;
+	}
+
 	ns3plug = 0;
 	memset(s3plug, 0, sizeof(s3plug));
 	ns3crc = 0;
@@ -475,7 +480,7 @@ static void free_chunks(struct imgchunk *fchunk, unsigned int *nfchunks)
 static void free_srecs(void)
 {
 	ns3data = 0;
-	memset(s3data, 0, sizeof(s3data));
+	kfree(s3data);
 	ns3plug = 0;
 	memset(s3plug, 0, sizeof(s3plug));
 	ns3crc = 0;
Signature · 1 line
1.9.1
maintainer
#1 lore raw
Quoted 7 lines · Sergio Paracuellos

This patch fix the following sparse warnings in prism2fw.c:
warning: memset with byte count of 120000

---
 drivers/staging/wlan-ng/prism2fw.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

Subject also wrong :(

#2 lore raw

PATCH 1/1 staging: wlan-ng: get memory from kernel allocators instead of big static buffer

This patch fix the following sparse warnings in prism2fw.c:
warning: memset with byte count of 120000

---
 drivers/staging/wlan-ng/prism2fw.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)
drivers/staging/wlan-ng/prism2fw.c +8 -3
index 96aa211..7e33048 100644
@@ -124,7 +124,7 @@ struct imgchunk {
 
 /* Data records */
 static unsigned int ns3data;
-static struct s3datarec s3data[S3DATA_MAX];
+static struct s3datarec *s3data;
 
 /* Plug records */
 static unsigned int ns3plug;
@@ -248,7 +248,12 @@ static int prism2_fwapply(const struct ihex_binrec *rfptr,
 
 	/* Initialize the data structures */
 	ns3data = 0;
-	memset(s3data, 0, sizeof(s3data));
+	s3data = kcalloc(S3DATA_MAX, sizeof(*s3data), GFP_KERNEL);
+	if (unlikely(!s3data)) {
+		result = -ENOMEM;
+		goto out;
+	}
+
 	ns3plug = 0;
 	memset(s3plug, 0, sizeof(s3plug));
 	ns3crc = 0;
@@ -475,7 +480,7 @@ static void free_chunks(struct imgchunk *fchunk, unsigned int *nfchunks)
 static void free_srecs(void)
 {
 	ns3data = 0;
-	memset(s3data, 0, sizeof(s3data));
+	kfree(s3data);
 	ns3plug = 0;
 	memset(s3plug, 0, sizeof(s3plug));
 	ns3crc = 0;
Signature · 1 line
1.9.1
#4 lore raw

PATCH 1/1 staging: wlan-ng: get memory from kernel allocators instead of big static buffer

In reply to Greg KH

This patch fix the following sparse warnings in prism2fw.c:
warning: memset with byte count of 120000

---
 drivers/staging/wlan-ng/prism2fw.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)
drivers/staging/wlan-ng/prism2fw.c +8 -3
index 96aa211..7e33048 100644
@@ -124,7 +124,7 @@ struct imgchunk {
 
 /* Data records */
 static unsigned int ns3data;
-static struct s3datarec s3data[S3DATA_MAX];
+static struct s3datarec *s3data;
 
 /* Plug records */
 static unsigned int ns3plug;
@@ -248,7 +248,12 @@ static int prism2_fwapply(const struct ihex_binrec *rfptr,
 
 	/* Initialize the data structures */
 	ns3data = 0;
-	memset(s3data, 0, sizeof(s3data));
+	s3data = kcalloc(S3DATA_MAX, sizeof(*s3data), GFP_KERNEL);
+	if (!s3data) {
+		result = -ENOMEM;
+		goto out;
+	}
+
 	ns3plug = 0;
 	memset(s3plug, 0, sizeof(s3plug));
 	ns3crc = 0;
@@ -475,7 +480,7 @@ static void free_chunks(struct imgchunk *fchunk, unsigned int *nfchunks)
 static void free_srecs(void)
 {
 	ns3data = 0;
-	memset(s3data, 0, sizeof(s3data));
+	kfree(s3data);
 	ns3plug = 0;
 	memset(s3plug, 0, sizeof(s3plug));
 	ns3crc = 0;
Signature · 1 line
1.9.1
maintainer
#3 lore raw

Re: [PATCH] staging: wlan-ng: get memory from kernel allocators instead of big static buffer

In reply to Sergio Paracuellos
Quoted 22 lines · Sergio Paracuellos

This patch fix the following sparse warnings in prism2fw.c:
warning: memset with byte count of 120000

---
 drivers/staging/wlan-ng/prism2fw.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)
drivers/staging/wlan-ng/prism2fw.c +1 -1
index 96aa211..7e33048 100644
@@ -124,7 +124,7 @@ struct imgchunk {
 
 /* Data records */
 static unsigned int ns3data;
-static struct s3datarec s3data[S3DATA_MAX];
+static struct s3datarec *s3data;
 
 /* Plug records */
 static unsigned int ns3plug;

drivers/staging/wlan-ng/prism2fw.c static int prism2_fwapply(const struct ihex_binrec *rfptr, · line 252

Quoted 6 lines
drivers/staging/wlan-ng/prism2fw.c +2 -1
@@ -248,7 +248,12 @@ static int prism2_fwapply(const struct ihex_binrec *rfptr,
 
 	/* Initialize the data structures */
 	ns3data = 0;
-	memset(s3data, 0, sizeof(s3data));
+	s3data = kcalloc(S3DATA_MAX, sizeof(*s3data), GFP_KERNEL);
+	if (unlikely(!s3data)) {

Unless you can measure the speed difference, NEVER use likely or unlikely in kernel code. The CPU and compiler knows better than you do what is going to happen, and optimizes it. Especially for allocating memory, that is a very common pattern and it knows what to do here.

Please remove this and resend.

thanks,

greg k-h

maintainer
#5 lore raw

Re: [PATCH] staging: wlan-ng: get memory from kernel allocators instead of big static buffer

In reply to Sergio Paracuellos
Quoted 7 lines · Sergio Paracuellos

This patch fix the following sparse warnings in prism2fw.c:
warning: memset with byte count of 120000

---
 drivers/staging/wlan-ng/prism2fw.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

Fastest patch review turn-around time ever :)

nice work, all now applied.

greg k-h

#6 lore raw

Re: [PATCH] staging: wlan-ng: get memory from kernel allocators instead of big static buffer

Just sitting in front of my laptop :) Thanks to you for code review!

Cheers,
Sergio Paracuello

Quoted 15 lines · Greg KH
Quoted 7 lines · Sergio Paracuellos

This patch fix the following sparse warnings in prism2fw.c:
warning: memset with byte count of 120000

---
  drivers/staging/wlan-ng/prism2fw.c | 11 ++++++++---
  1 file changed, 8 insertions(+), 3 deletions(-)

Fastest patch review turn-around time ever :)

nice work, all now applied.

greg k-h