cifs: constify get_normalized_path() properly

As it is, it takes const char * and, in some cases, stores it in
caller's variable that is plain char *.  Fortunately, none of the
callers actually proceeded to modify the string via now-non-const
alias, but that's trouble waiting to happen.

It's easy to do properly, anyway...

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
Signed-off-by: Steve French <stfrench@microsoft.com>
This commit is contained in:
Al Viro 2021-03-18 01:03:34 -04:00 committed by Steve French
parent 8d76722355
commit 9cfdb1c12b

View file

@ -81,23 +81,24 @@ static void refresh_cache_worker(struct work_struct *work);
static DECLARE_DELAYED_WORK(refresh_task, refresh_cache_worker); static DECLARE_DELAYED_WORK(refresh_task, refresh_cache_worker);
static int get_normalized_path(const char *path, char **npath) static int get_normalized_path(const char *path, const char **npath)
{ {
if (!path || strlen(path) < 3 || (*path != '\\' && *path != '/')) if (!path || strlen(path) < 3 || (*path != '\\' && *path != '/'))
return -EINVAL; return -EINVAL;
if (*path == '\\') { if (*path == '\\') {
*npath = (char *)path; *npath = path;
} else { } else {
*npath = kstrdup(path, GFP_KERNEL); char *s = kstrdup(path, GFP_KERNEL);
if (!*npath) if (!s)
return -ENOMEM; return -ENOMEM;
convert_delimiter(*npath, '\\'); convert_delimiter(s, '\\');
*npath = s;
} }
return 0; return 0;
} }
static inline void free_normalized_path(const char *path, char *npath) static inline void free_normalized_path(const char *path, const char *npath)
{ {
if (path != npath) if (path != npath)
kfree(npath); kfree(npath);
@ -882,7 +883,7 @@ int dfs_cache_find(const unsigned int xid, struct cifs_ses *ses,
struct dfs_cache_tgt_list *tgt_list) struct dfs_cache_tgt_list *tgt_list)
{ {
int rc; int rc;
char *npath; const char *npath;
struct cache_entry *ce; struct cache_entry *ce;
rc = get_normalized_path(path, &npath); rc = get_normalized_path(path, &npath);
@ -936,7 +937,7 @@ int dfs_cache_noreq_find(const char *path, struct dfs_info3_param *ref,
struct dfs_cache_tgt_list *tgt_list) struct dfs_cache_tgt_list *tgt_list)
{ {
int rc; int rc;
char *npath; const char *npath;
struct cache_entry *ce; struct cache_entry *ce;
rc = get_normalized_path(path, &npath); rc = get_normalized_path(path, &npath);
@ -991,7 +992,7 @@ int dfs_cache_update_tgthint(const unsigned int xid, struct cifs_ses *ses,
const struct dfs_cache_tgt_iterator *it) const struct dfs_cache_tgt_iterator *it)
{ {
int rc; int rc;
char *npath; const char *npath;
struct cache_entry *ce; struct cache_entry *ce;
struct cache_dfs_tgt *t; struct cache_dfs_tgt *t;
@ -1053,7 +1054,7 @@ int dfs_cache_noreq_update_tgthint(const char *path,
const struct dfs_cache_tgt_iterator *it) const struct dfs_cache_tgt_iterator *it)
{ {
int rc; int rc;
char *npath; const char *npath;
struct cache_entry *ce; struct cache_entry *ce;
struct cache_dfs_tgt *t; struct cache_dfs_tgt *t;
@ -1111,7 +1112,7 @@ int dfs_cache_get_tgt_referral(const char *path,
struct dfs_info3_param *ref) struct dfs_info3_param *ref)
{ {
int rc; int rc;
char *npath; const char *npath;
struct cache_entry *ce; struct cache_entry *ce;
if (!it || !ref) if (!it || !ref)
@ -1484,7 +1485,7 @@ static int refresh_tcon(struct vol_info *vi, struct cifs_tcon *tcon)
{ {
int rc = 0; int rc = 0;
unsigned int xid; unsigned int xid;
char *path, *npath; const char *path, *npath;
struct cache_entry *ce; struct cache_entry *ce;
struct cifs_ses *root_ses = NULL, *ses; struct cifs_ses *root_ses = NULL, *ses;
struct dfs_info3_param *refs = NULL; struct dfs_info3_param *refs = NULL;