* [PATCH v2] staging: rtl8192e: Replace strcpy with strcat in rtl819x_translate_scan
@ 2024-08-23 15:34 Abhishek Tamboli
2024-08-24 5:45 ` Greg KH
2024-08-24 11:21 ` Dan Carpenter
0 siblings, 2 replies; 5+ messages in thread
From: Abhishek Tamboli @ 2024-08-23 15:34 UTC (permalink / raw)
To: gregkh
Cc: tdavies, philipp.g.hortmann, garyrookard, linux-staging, skhan,
rbmarliere, dan.carpenter, christophe.jaillet,
linux-kernel-mentees, linux-kernel
Replace strcpy() with strcat() in rtl819x_translate_scan()
Also Fix proto_name[] buffer size issue to accommodate all
network modes.
Signed-off-by: Abhishek Tamboli <abhishektamboli9@gmail.com>
---
Changes in v2:
- Revert the use of strscpy and replaced it with strcat.
- Remove the 'pname' and replace it's usage with direct
operations on 'proto_name' buffer.
drivers/staging/rtl8192e/rtllib_wx.c | 13 ++++++-------
1 file changed, 6 insertions(+), 7 deletions(-)
diff --git a/drivers/staging/rtl8192e/rtllib_wx.c b/drivers/staging/rtl8192e/rtllib_wx.c
index fbd4ec824084..ec0c4c5bade7 100644
--- a/drivers/staging/rtl8192e/rtllib_wx.c
+++ b/drivers/staging/rtl8192e/rtllib_wx.c
@@ -23,14 +23,14 @@ static const char * const rtllib_modes[] = {
};
#define MAX_CUSTOM_LEN 64
+#define MAX_PROTO_NAME_LEN 10
static inline char *rtl819x_translate_scan(struct rtllib_device *ieee,
char *start, char *stop,
struct rtllib_network *network,
struct iw_request_info *info)
{
char custom[MAX_CUSTOM_LEN];
- char proto_name[6];
- char *pname = proto_name;
+ char proto_name[MAX_PROTO_NAME_LEN];
char *p;
struct iw_event iwe;
int i, j;
@@ -59,13 +59,12 @@ static inline char *rtl819x_translate_scan(struct rtllib_device *ieee,
}
/* Add the protocol name */
iwe.cmd = SIOCGIWNAME;
+ /* Initialise proto_name as an empty string*/
+ memset(proto_name, '\0', sizeof(proto_name));
for (i = 0; i < ARRAY_SIZE(rtllib_modes); i++) {
- if (network->mode & BIT(i)) {
- strcpy(pname, rtllib_modes[i]);
- pname += strlen(rtllib_modes[i]);
+ if (network->mode & BIT(i))
+ strcat(proto_name, rtllib_modes[i]);
}
- }
- *pname = '\0';
snprintf(iwe.u.name, IFNAMSIZ, "IEEE802.11%s", proto_name);
start = iwe_stream_add_event(info, start, stop, &iwe, IW_EV_CHAR_LEN);
/* Add mode */
--
2.34.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH v2] staging: rtl8192e: Replace strcpy with strcat in rtl819x_translate_scan
2024-08-23 15:34 [PATCH v2] staging: rtl8192e: Replace strcpy with strcat in rtl819x_translate_scan Abhishek Tamboli
@ 2024-08-24 5:45 ` Greg KH
2024-08-24 16:59 ` Abhishek Tamboli
2024-08-24 11:21 ` Dan Carpenter
1 sibling, 1 reply; 5+ messages in thread
From: Greg KH @ 2024-08-24 5:45 UTC (permalink / raw)
To: Abhishek Tamboli
Cc: tdavies, philipp.g.hortmann, garyrookard, linux-staging, skhan,
rbmarliere, dan.carpenter, christophe.jaillet,
linux-kernel-mentees, linux-kernel
On Fri, Aug 23, 2024 at 09:04:11PM +0530, Abhishek Tamboli wrote:
> Replace strcpy() with strcat() in rtl819x_translate_scan()
> Also Fix proto_name[] buffer size issue to accommodate all
> network modes.
When you say "also" in a changelog text, that's a huge hint that this
should probably be split up into multiple changes. Please do that here.
More comments below.
> Signed-off-by: Abhishek Tamboli <abhishektamboli9@gmail.com>
> ---
> Changes in v2:
> - Revert the use of strscpy and replaced it with strcat.
> - Remove the 'pname' and replace it's usage with direct
> operations on 'proto_name' buffer.
>
> drivers/staging/rtl8192e/rtllib_wx.c | 13 ++++++-------
> 1 file changed, 6 insertions(+), 7 deletions(-)
>
> diff --git a/drivers/staging/rtl8192e/rtllib_wx.c b/drivers/staging/rtl8192e/rtllib_wx.c
> index fbd4ec824084..ec0c4c5bade7 100644
> --- a/drivers/staging/rtl8192e/rtllib_wx.c
> +++ b/drivers/staging/rtl8192e/rtllib_wx.c
> @@ -23,14 +23,14 @@ static const char * const rtllib_modes[] = {
> };
>
> #define MAX_CUSTOM_LEN 64
> +#define MAX_PROTO_NAME_LEN 10
Where did this "10" come from? What sets this limit? Why not 100?
1000? 2? You get the idea :)
> static inline char *rtl819x_translate_scan(struct rtllib_device *ieee,
> char *start, char *stop,
> struct rtllib_network *network,
> struct iw_request_info *info)
> {
> char custom[MAX_CUSTOM_LEN];
> - char proto_name[6];
> - char *pname = proto_name;
> + char proto_name[MAX_PROTO_NAME_LEN];
> char *p;
> struct iw_event iwe;
> int i, j;
> @@ -59,13 +59,12 @@ static inline char *rtl819x_translate_scan(struct rtllib_device *ieee,
> }
> /* Add the protocol name */
> iwe.cmd = SIOCGIWNAME;
> + /* Initialise proto_name as an empty string*/
> + memset(proto_name, '\0', sizeof(proto_name));
> for (i = 0; i < ARRAY_SIZE(rtllib_modes); i++) {
> - if (network->mode & BIT(i)) {
> - strcpy(pname, rtllib_modes[i]);
> - pname += strlen(rtllib_modes[i]);
> + if (network->mode & BIT(i))
> + strcat(proto_name, rtllib_modes[i]);
> }
> - }
I think the } placement is now incorrect, right? Did you run checkpatch
on this change?
thanks,
greg k-h
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v2] staging: rtl8192e: Replace strcpy with strcat in rtl819x_translate_scan
2024-08-23 15:34 [PATCH v2] staging: rtl8192e: Replace strcpy with strcat in rtl819x_translate_scan Abhishek Tamboli
2024-08-24 5:45 ` Greg KH
@ 2024-08-24 11:21 ` Dan Carpenter
2024-08-24 17:09 ` Abhishek Tamboli
1 sibling, 1 reply; 5+ messages in thread
From: Dan Carpenter @ 2024-08-24 11:21 UTC (permalink / raw)
To: Abhishek Tamboli
Cc: gregkh, tdavies, philipp.g.hortmann, garyrookard, linux-staging,
skhan, rbmarliere, christophe.jaillet, linux-kernel-mentees,
linux-kernel
On Fri, Aug 23, 2024 at 09:04:11PM +0530, Abhishek Tamboli wrote:
> diff --git a/drivers/staging/rtl8192e/rtllib_wx.c b/drivers/staging/rtl8192e/rtllib_wx.c
> index fbd4ec824084..ec0c4c5bade7 100644
> --- a/drivers/staging/rtl8192e/rtllib_wx.c
> +++ b/drivers/staging/rtl8192e/rtllib_wx.c
> @@ -23,14 +23,14 @@ static const char * const rtllib_modes[] = {
> };
>
> #define MAX_CUSTOM_LEN 64
> +#define MAX_PROTO_NAME_LEN 10
> static inline char *rtl819x_translate_scan(struct rtllib_device *ieee,
> char *start, char *stop,
> struct rtllib_network *network,
> struct iw_request_info *info)
> {
> char custom[MAX_CUSTOM_LEN];
> - char proto_name[6];
> - char *pname = proto_name;
> + char proto_name[MAX_PROTO_NAME_LEN];
In the end I think we don't want to make this buffer larger. But if we did
this define is really vague and slightly confusing. I assumed it was something
else when I read it. It hurts readability. It would probably be better to just
leave it as 6 instead and add a comment. /* Large enough to hold "N-24G" */
> char *p;
> struct iw_event iwe;
> int i, j;
> @@ -59,13 +59,12 @@ static inline char *rtl819x_translate_scan(struct rtllib_device *ieee,
> }
> /* Add the protocol name */
> iwe.cmd = SIOCGIWNAME;
> + /* Initialise proto_name as an empty string*/
This comment doesn't add any information. Every kernel developer knows what
memset() does.
> + memset(proto_name, '\0', sizeof(proto_name));
Normally we would just say 0 instead of '\0'. The other way to do this would
be to initialize it at the start:
char proto_name[6] = "";
regards,
dan carpenter
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v2] staging: rtl8192e: Replace strcpy with strcat in rtl819x_translate_scan
2024-08-24 5:45 ` Greg KH
@ 2024-08-24 16:59 ` Abhishek Tamboli
0 siblings, 0 replies; 5+ messages in thread
From: Abhishek Tamboli @ 2024-08-24 16:59 UTC (permalink / raw)
To: Greg KH
Cc: tdavies, philipp.g.hortmann, garyrookard, linux-staging, skhan,
rbmarliere, dan.carpenter, christophe.jaillet,
linux-kernel-mentees, linux-kernel
On Sat, Aug 24, 2024 at 01:45:00PM +0800, Greg KH wrote:
> On Fri, Aug 23, 2024 at 09:04:11PM +0530, Abhishek Tamboli wrote:
> > Replace strcpy() with strcat() in rtl819x_translate_scan()
> > Also Fix proto_name[] buffer size issue to accommodate all
> > network modes.
>
> When you say "also" in a changelog text, that's a huge hint that this
> should probably be split up into multiple changes. Please do that here.
Sure, I'll do it.
> More comments below.
>
> > Signed-off-by: Abhishek Tamboli <abhishektamboli9@gmail.com>
> > ---
> > Changes in v2:
> > - Revert the use of strscpy and replaced it with strcat.
> > - Remove the 'pname' and replace it's usage with direct
> > operations on 'proto_name' buffer.
> >
> > drivers/staging/rtl8192e/rtllib_wx.c | 13 ++++++-------
> > 1 file changed, 6 insertions(+), 7 deletions(-)
> >
> > diff --git a/drivers/staging/rtl8192e/rtllib_wx.c b/drivers/staging/rtl8192e/rtllib_wx.c
> > index fbd4ec824084..ec0c4c5bade7 100644
> > --- a/drivers/staging/rtl8192e/rtllib_wx.c
> > +++ b/drivers/staging/rtl8192e/rtllib_wx.c
> > @@ -23,14 +23,14 @@ static const char * const rtllib_modes[] = {
> > };
> >
> > #define MAX_CUSTOM_LEN 64
> > +#define MAX_PROTO_NAME_LEN 10
>
> Where did this "10" come from? What sets this limit? Why not 100?
> 1000? 2? You get the idea :)
>
yes, I got it.
> > static inline char *rtl819x_translate_scan(struct rtllib_device *ieee,
> > char *start, char *stop,
> > struct rtllib_network *network,
> > struct iw_request_info *info)
> > {
> > char custom[MAX_CUSTOM_LEN];
> > - char proto_name[6];
> > - char *pname = proto_name;
> > + char proto_name[MAX_PROTO_NAME_LEN];
> > char *p;
> > struct iw_event iwe;
> > int i, j;
> > @@ -59,13 +59,12 @@ static inline char *rtl819x_translate_scan(struct rtllib_device *ieee,
> > }
> > /* Add the protocol name */
> > iwe.cmd = SIOCGIWNAME;
> > + /* Initialise proto_name as an empty string*/
> > + memset(proto_name, '\0', sizeof(proto_name));
> > for (i = 0; i < ARRAY_SIZE(rtllib_modes); i++) {
> > - if (network->mode & BIT(i)) {
> > - strcpy(pname, rtllib_modes[i]);
> > - pname += strlen(rtllib_modes[i]);
> > + if (network->mode & BIT(i))
> > + strcat(proto_name, rtllib_modes[i]);
> > }
> > - }
>
> I think the } placement is now incorrect, right? Did you run checkpatch
> on this change?
Yes, I do run the checkpatch on this change and didn't get any warnings
or errors.
Thanks, for the feedback. I'll do the changes.
Regards,
Abhishek
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v2] staging: rtl8192e: Replace strcpy with strcat in rtl819x_translate_scan
2024-08-24 11:21 ` Dan Carpenter
@ 2024-08-24 17:09 ` Abhishek Tamboli
0 siblings, 0 replies; 5+ messages in thread
From: Abhishek Tamboli @ 2024-08-24 17:09 UTC (permalink / raw)
To: Dan Carpenter
Cc: gregkh, tdavies, philipp.g.hortmann, garyrookard, linux-staging,
skhan, rbmarliere, christophe.jaillet, linux-kernel-mentees,
linux-kernel
On Sat, Aug 24, 2024 at 02:21:47PM +0300, Dan Carpenter wrote:
> On Fri, Aug 23, 2024 at 09:04:11PM +0530, Abhishek Tamboli wrote:
> > diff --git a/drivers/staging/rtl8192e/rtllib_wx.c b/drivers/staging/rtl8192e/rtllib_wx.c
> > index fbd4ec824084..ec0c4c5bade7 100644
> > --- a/drivers/staging/rtl8192e/rtllib_wx.c
> > +++ b/drivers/staging/rtl8192e/rtllib_wx.c
> > @@ -23,14 +23,14 @@ static const char * const rtllib_modes[] = {
> > };
> >
> > #define MAX_CUSTOM_LEN 64
> > +#define MAX_PROTO_NAME_LEN 10
> > static inline char *rtl819x_translate_scan(struct rtllib_device *ieee,
> > char *start, char *stop,
> > struct rtllib_network *network,
> > struct iw_request_info *info)
> > {
> > char custom[MAX_CUSTOM_LEN];
> > - char proto_name[6];
> > - char *pname = proto_name;
> > + char proto_name[MAX_PROTO_NAME_LEN];
>
> In the end I think we don't want to make this buffer larger. But if we did
> this define is really vague and slightly confusing. I assumed it was something
> else when I read it. It hurts readability. It would probably be better to just
> leave it as 6 instead and add a comment. /* Large enough to hold "N-24G" */
Okay, I'll revert the buffer size to 6.
>
> > char *p;
> > struct iw_event iwe;
> > int i, j;
> > @@ -59,13 +59,12 @@ static inline char *rtl819x_translate_scan(struct rtllib_device *ieee,
> > }
> > /* Add the protocol name */
> > iwe.cmd = SIOCGIWNAME;
> > + /* Initialise proto_name as an empty string*/
>
> This comment doesn't add any information. Every kernel developer knows what
> memset() does.
Sure, I'll remove it.
> > + memset(proto_name, '\0', sizeof(proto_name));
>
> Normally we would just say 0 instead of '\0'. The other way to do this would
> be to initialize it at the start:
>
> char proto_name[6] = "";
>
Thanks, for the feedback. I'll do the changes.
Regards,
Abhishek
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2024-08-24 17:09 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-08-23 15:34 [PATCH v2] staging: rtl8192e: Replace strcpy with strcat in rtl819x_translate_scan Abhishek Tamboli
2024-08-24 5:45 ` Greg KH
2024-08-24 16:59 ` Abhishek Tamboli
2024-08-24 11:21 ` Dan Carpenter
2024-08-24 17:09 ` Abhishek Tamboli
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).