linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] staging: ks7010: honor 'const' qualifier
@ 2016-06-15 21:53 Arnd Bergmann
  2016-06-17  8:26 ` Wolfram Sang
  0 siblings, 1 reply; 3+ messages in thread
From: Arnd Bergmann @ 2016-06-15 21:53 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Wolfram Sang; +Cc: Arnd Bergmann, devel, linux-kernel

The recently-added ks7010 driver produces an annoying build warning:

drivers/staging/ks7010/ks7010_config.c: In function 'ks_wlan_read_config_file':
drivers/staging/ks7010/ks7010_config.c:263:8: error: assignment discards 'const' qualifier from pointer target type [-Werror=discarded-qualifiers]

The problem here is that it assigns the firmware data to a non-const
variable, and then goes on to modify it, which is clearly not the intended
use case.

The only modification is to set the last byte to '\0', and as far as
I can tell, this modification is unnecessary, as the parser always compares
against the end pointer, rather than relying on zero-termination.

This patch therefore removes the modification of the const data and marks
all the pointers 'const to avoid the warning.

Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
 drivers/staging/ks7010/ks7010_config.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/drivers/staging/ks7010/ks7010_config.c b/drivers/staging/ks7010/ks7010_config.c
index 4b495cbef481..945ff6c7f419 100644
--- a/drivers/staging/ks7010/ks7010_config.c
+++ b/drivers/staging/ks7010/ks7010_config.c
@@ -16,7 +16,7 @@ static int wep_type;
 
 static
 void analyze_character_wep_key(struct ks_wlan_parameter *param,
-			       int wep_key_index, char *value)
+			       int wep_key_index, const char *value)
 {
 	int i;
 	unsigned char wep_key[26], key_length;
@@ -39,7 +39,7 @@ void analyze_character_wep_key(struct ks_wlan_parameter *param,
 
 static
 void analyze_hex_wep_key(struct ks_wlan_parameter *param, int wep_key_index,
-			 char *value)
+			 const char *value)
 {
 	unsigned char wep_end[26], i, j, key_length;
 
@@ -93,7 +93,7 @@ void analyze_hex_wep_key(struct ks_wlan_parameter *param, int wep_key_index,
 }
 
 static
-int rate_set_configuration(struct ks_wlan_private *priv, char *value)
+int rate_set_configuration(struct ks_wlan_private *priv, const char *value)
 {
 	int rc = 0;
 
@@ -204,9 +204,10 @@ int ks_wlan_read_config_file(struct ks_wlan_private *priv)
 
 	const struct firmware *fw_entry;
 	struct device *dev = NULL;
-	char cfg_file[] = CFG_FILE;
-	char *cur_p, *end_p;
-	char wk_buff[256], *wk_p;
+	const char cfg_file[] = CFG_FILE;
+	const char *cur_p, *end_p;
+	char wk_buff[256];
+	const char *wk_p;
 
 	/* Initialize Variable */
 	priv->reg.operation_mode = MODE_INFRASTRUCTURE;	/* Infrastructure */
@@ -262,7 +263,6 @@ int ks_wlan_read_config_file(struct ks_wlan_private *priv)
 		fw_entry->size);
 	cur_p = fw_entry->data;
 	end_p = cur_p + fw_entry->size;
-	*end_p = '\0';
 
 	while (cur_p < end_p) {
 		int i, j, len;
-- 
2.9.0

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

* Re: [PATCH] staging: ks7010: honor 'const' qualifier
  2016-06-15 21:53 [PATCH] staging: ks7010: honor 'const' qualifier Arnd Bergmann
@ 2016-06-17  8:26 ` Wolfram Sang
  2016-06-17  8:52   ` Arnd Bergmann
  0 siblings, 1 reply; 3+ messages in thread
From: Wolfram Sang @ 2016-06-17  8:26 UTC (permalink / raw)
  To: Arnd Bergmann; +Cc: Greg Kroah-Hartman, Wolfram Sang, devel, linux-kernel

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

On Wed, Jun 15, 2016 at 11:53:11PM +0200, Arnd Bergmann wrote:
> The recently-added ks7010 driver produces an annoying build warning:
> 
> drivers/staging/ks7010/ks7010_config.c: In function 'ks_wlan_read_config_file':
> drivers/staging/ks7010/ks7010_config.c:263:8: error: assignment discards 'const' qualifier from pointer target type [-Werror=discarded-qualifiers]
> 
> The problem here is that it assigns the firmware data to a non-const
> variable, and then goes on to modify it, which is clearly not the intended
> use case.
> 
> The only modification is to set the last byte to '\0', and as far as
> I can tell, this modification is unnecessary, as the parser always compares
> against the end pointer, rather than relying on zero-termination.
> 
> This patch therefore removes the modification of the const data and marks
> all the pointers 'const to avoid the warning.
> 
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>

Thanks! I'll send in a second a patch, though, which removes the config
file handling completely.

   Wolfram


[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

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

* Re: [PATCH] staging: ks7010: honor 'const' qualifier
  2016-06-17  8:26 ` Wolfram Sang
@ 2016-06-17  8:52   ` Arnd Bergmann
  0 siblings, 0 replies; 3+ messages in thread
From: Arnd Bergmann @ 2016-06-17  8:52 UTC (permalink / raw)
  To: Wolfram Sang; +Cc: Greg Kroah-Hartman, Wolfram Sang, devel, linux-kernel

On Friday, June 17, 2016 10:26:38 AM CEST Wolfram Sang wrote:
> On Wed, Jun 15, 2016 at 11:53:11PM +0200, Arnd Bergmann wrote:
> > The recently-added ks7010 driver produces an annoying build warning:
> > 
> > drivers/staging/ks7010/ks7010_config.c: In function 'ks_wlan_read_config_file':
> > drivers/staging/ks7010/ks7010_config.c:263:8: error: assignment discards 'const' qualifier from pointer target type [-Werror=discarded-qualifiers]
> > 
> > The problem here is that it assigns the firmware data to a non-const
> > variable, and then goes on to modify it, which is clearly not the intended
> > use case.
> > 
> > The only modification is to set the last byte to '\0', and as far as
> > I can tell, this modification is unnecessary, as the parser always compares
> > against the end pointer, rather than relying on zero-termination.
> > 
> > This patch therefore removes the modification of the const data and marks
> > all the pointers 'const to avoid the warning.
> > 
> > Signed-off-by: Arnd Bergmann <arnd@arndb.de>
> 
> Thanks! I'll send in a second a patch, though, which removes the config
> file handling completely.

Ok, perfect!

	Arnd

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

end of thread, other threads:[~2016-06-17  8:50 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-06-15 21:53 [PATCH] staging: ks7010: honor 'const' qualifier Arnd Bergmann
2016-06-17  8:26 ` Wolfram Sang
2016-06-17  8:52   ` Arnd Bergmann

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).