2020-05-11 15:51:14 +02:00
// SPDX-License-Identifier: GPL-2.0-or-later
/*
* RDMA Transport Layer
*
* Copyright ( c ) 2014 - 2018 ProfitBricks GmbH . All rights reserved .
* Copyright ( c ) 2018 - 2019 1 & 1 IONOS Cloud GmbH . All rights reserved .
* Copyright ( c ) 2019 - 2020 1 & 1 IONOS SE . All rights reserved .
*/
# undef pr_fmt
# define pr_fmt(fmt) KBUILD_MODNAME " L" __stringify(__LINE__) ": " fmt
# include "rtrs-pri.h"
# include "rtrs-clt.h"
# include "rtrs-log.h"
# define MIN_MAX_RECONN_ATT -1
# define MAX_MAX_RECONN_ATT 9999
2022-01-05 19:07:06 +01:00
static void rtrs_clt_path_release ( struct kobject * kobj )
2020-05-11 15:51:14 +02:00
{
2022-01-05 19:07:06 +01:00
struct rtrs_clt_path * clt_path ;
2020-05-11 15:51:14 +02:00
2022-01-05 19:07:06 +01:00
clt_path = container_of ( kobj , struct rtrs_clt_path , kobj ) ;
2020-05-11 15:51:14 +02:00
2022-01-05 19:07:06 +01:00
free_path ( clt_path ) ;
2020-05-11 15:51:14 +02:00
}
static struct kobj_type ktype_sess = {
. sysfs_ops = & kobj_sysfs_ops ,
2022-01-05 19:07:06 +01:00
. release = rtrs_clt_path_release
2020-05-11 15:51:14 +02:00
} ;
2022-01-05 19:07:06 +01:00
static void rtrs_clt_path_stats_release ( struct kobject * kobj )
2020-05-11 15:51:14 +02:00
{
struct rtrs_clt_stats * stats ;
stats = container_of ( kobj , struct rtrs_clt_stats , kobj_stats ) ;
free_percpu ( stats - > pcpu_stats ) ;
kfree ( stats ) ;
}
static struct kobj_type ktype_stats = {
. sysfs_ops = & kobj_sysfs_ops ,
2022-01-05 19:07:06 +01:00
. release = rtrs_clt_path_stats_release ,
2020-05-11 15:51:14 +02:00
} ;
static ssize_t max_reconnect_attempts_show ( struct device * dev ,
struct device_attribute * attr ,
char * page )
{
2022-01-05 19:07:08 +01:00
struct rtrs_clt_sess * clt = container_of ( dev , struct rtrs_clt_sess ,
dev ) ;
2020-05-11 15:51:14 +02:00
RDMA: Convert sysfs device * show functions to use sysfs_emit()
Done with cocci script:
@@
identifier d_show;
identifier dev, attr, buf;
@@
ssize_t d_show(struct device *dev, struct device_attribute *attr, char *buf)
{
<...
return
- sprintf(buf,
+ sysfs_emit(buf,
...);
...>
}
@@
identifier d_show;
identifier dev, attr, buf;
@@
ssize_t d_show(struct device *dev, struct device_attribute *attr, char *buf)
{
<...
return
- snprintf(buf, PAGE_SIZE,
+ sysfs_emit(buf,
...);
...>
}
@@
identifier d_show;
identifier dev, attr, buf;
@@
ssize_t d_show(struct device *dev, struct device_attribute *attr, char *buf)
{
<...
return
- scnprintf(buf, PAGE_SIZE,
+ sysfs_emit(buf,
...);
...>
}
@@
identifier d_show;
identifier dev, attr, buf;
expression chr;
@@
ssize_t d_show(struct device *dev, struct device_attribute *attr, char *buf)
{
<...
return
- strcpy(buf, chr);
+ sysfs_emit(buf, chr);
...>
}
@@
identifier d_show;
identifier dev, attr, buf;
identifier len;
@@
ssize_t d_show(struct device *dev, struct device_attribute *attr, char *buf)
{
<...
len =
- sprintf(buf,
+ sysfs_emit(buf,
...);
...>
return len;
}
@@
identifier d_show;
identifier dev, attr, buf;
identifier len;
@@
ssize_t d_show(struct device *dev, struct device_attribute *attr, char *buf)
{
<...
len =
- snprintf(buf, PAGE_SIZE,
+ sysfs_emit(buf,
...);
...>
return len;
}
@@
identifier d_show;
identifier dev, attr, buf;
identifier len;
@@
ssize_t d_show(struct device *dev, struct device_attribute *attr, char *buf)
{
<...
len =
- scnprintf(buf, PAGE_SIZE,
+ sysfs_emit(buf,
...);
...>
return len;
}
@@
identifier d_show;
identifier dev, attr, buf;
identifier len;
@@
ssize_t d_show(struct device *dev, struct device_attribute *attr, char *buf)
{
<...
- len += scnprintf(buf + len, PAGE_SIZE - len,
+ len += sysfs_emit_at(buf, len,
...);
...>
return len;
}
@@
identifier d_show;
identifier dev, attr, buf;
expression chr;
@@
ssize_t d_show(struct device *dev, struct device_attribute *attr, char *buf)
{
...
- strcpy(buf, chr);
- return strlen(buf);
+ return sysfs_emit(buf, chr);
}
Link: https://lore.kernel.org/r/7f406fa8e3aa2552c022bec680f621e38d1fe414.1602122879.git.joe@perches.com
Signed-off-by: Joe Perches <joe@perches.com>
Reviewed-by: Jason Gunthorpe <jgg@nvidia.com>
Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
2020-10-07 19:36:24 -07:00
return sysfs_emit ( page , " %d \n " ,
rtrs_clt_get_max_reconnect_attempts ( clt ) ) ;
2020-05-11 15:51:14 +02:00
}
static ssize_t max_reconnect_attempts_store ( struct device * dev ,
struct device_attribute * attr ,
const char * buf ,
size_t count )
{
int value ;
int ret ;
2022-01-05 19:07:08 +01:00
struct rtrs_clt_sess * clt = container_of ( dev , struct rtrs_clt_sess ,
dev ) ;
2020-05-11 15:51:14 +02:00
ret = kstrtoint ( buf , 10 , & value ) ;
if ( ret ) {
rtrs_err ( clt , " %s: failed to convert string '%s' to int \n " ,
attr - > attr . name , buf ) ;
return ret ;
}
if ( value > MAX_MAX_RECONN_ATT | |
value < MIN_MAX_RECONN_ATT ) {
rtrs_err ( clt ,
" %s: invalid range (provided: '%s', accepted: min: %d, max: %d) \n " ,
attr - > attr . name , buf , MIN_MAX_RECONN_ATT ,
MAX_MAX_RECONN_ATT ) ;
return - EINVAL ;
}
rtrs_clt_set_max_reconnect_attempts ( clt , value ) ;
return count ;
}
static DEVICE_ATTR_RW ( max_reconnect_attempts ) ;
static ssize_t mpath_policy_show ( struct device * dev ,
struct device_attribute * attr ,
char * page )
{
2022-01-05 19:07:08 +01:00
struct rtrs_clt_sess * clt ;
2020-05-11 15:51:14 +02:00
2022-01-05 19:07:08 +01:00
clt = container_of ( dev , struct rtrs_clt_sess , dev ) ;
2020-05-11 15:51:14 +02:00
switch ( clt - > mp_policy ) {
case MP_POLICY_RR :
RDMA: Convert sysfs device * show functions to use sysfs_emit()
Done with cocci script:
@@
identifier d_show;
identifier dev, attr, buf;
@@
ssize_t d_show(struct device *dev, struct device_attribute *attr, char *buf)
{
<...
return
- sprintf(buf,
+ sysfs_emit(buf,
...);
...>
}
@@
identifier d_show;
identifier dev, attr, buf;
@@
ssize_t d_show(struct device *dev, struct device_attribute *attr, char *buf)
{
<...
return
- snprintf(buf, PAGE_SIZE,
+ sysfs_emit(buf,
...);
...>
}
@@
identifier d_show;
identifier dev, attr, buf;
@@
ssize_t d_show(struct device *dev, struct device_attribute *attr, char *buf)
{
<...
return
- scnprintf(buf, PAGE_SIZE,
+ sysfs_emit(buf,
...);
...>
}
@@
identifier d_show;
identifier dev, attr, buf;
expression chr;
@@
ssize_t d_show(struct device *dev, struct device_attribute *attr, char *buf)
{
<...
return
- strcpy(buf, chr);
+ sysfs_emit(buf, chr);
...>
}
@@
identifier d_show;
identifier dev, attr, buf;
identifier len;
@@
ssize_t d_show(struct device *dev, struct device_attribute *attr, char *buf)
{
<...
len =
- sprintf(buf,
+ sysfs_emit(buf,
...);
...>
return len;
}
@@
identifier d_show;
identifier dev, attr, buf;
identifier len;
@@
ssize_t d_show(struct device *dev, struct device_attribute *attr, char *buf)
{
<...
len =
- snprintf(buf, PAGE_SIZE,
+ sysfs_emit(buf,
...);
...>
return len;
}
@@
identifier d_show;
identifier dev, attr, buf;
identifier len;
@@
ssize_t d_show(struct device *dev, struct device_attribute *attr, char *buf)
{
<...
len =
- scnprintf(buf, PAGE_SIZE,
+ sysfs_emit(buf,
...);
...>
return len;
}
@@
identifier d_show;
identifier dev, attr, buf;
identifier len;
@@
ssize_t d_show(struct device *dev, struct device_attribute *attr, char *buf)
{
<...
- len += scnprintf(buf + len, PAGE_SIZE - len,
+ len += sysfs_emit_at(buf, len,
...);
...>
return len;
}
@@
identifier d_show;
identifier dev, attr, buf;
expression chr;
@@
ssize_t d_show(struct device *dev, struct device_attribute *attr, char *buf)
{
...
- strcpy(buf, chr);
- return strlen(buf);
+ return sysfs_emit(buf, chr);
}
Link: https://lore.kernel.org/r/7f406fa8e3aa2552c022bec680f621e38d1fe414.1602122879.git.joe@perches.com
Signed-off-by: Joe Perches <joe@perches.com>
Reviewed-by: Jason Gunthorpe <jgg@nvidia.com>
Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
2020-10-07 19:36:24 -07:00
return sysfs_emit ( page , " round-robin (RR: %d) \n " ,
clt - > mp_policy ) ;
2020-05-11 15:51:14 +02:00
case MP_POLICY_MIN_INFLIGHT :
RDMA: Convert sysfs device * show functions to use sysfs_emit()
Done with cocci script:
@@
identifier d_show;
identifier dev, attr, buf;
@@
ssize_t d_show(struct device *dev, struct device_attribute *attr, char *buf)
{
<...
return
- sprintf(buf,
+ sysfs_emit(buf,
...);
...>
}
@@
identifier d_show;
identifier dev, attr, buf;
@@
ssize_t d_show(struct device *dev, struct device_attribute *attr, char *buf)
{
<...
return
- snprintf(buf, PAGE_SIZE,
+ sysfs_emit(buf,
...);
...>
}
@@
identifier d_show;
identifier dev, attr, buf;
@@
ssize_t d_show(struct device *dev, struct device_attribute *attr, char *buf)
{
<...
return
- scnprintf(buf, PAGE_SIZE,
+ sysfs_emit(buf,
...);
...>
}
@@
identifier d_show;
identifier dev, attr, buf;
expression chr;
@@
ssize_t d_show(struct device *dev, struct device_attribute *attr, char *buf)
{
<...
return
- strcpy(buf, chr);
+ sysfs_emit(buf, chr);
...>
}
@@
identifier d_show;
identifier dev, attr, buf;
identifier len;
@@
ssize_t d_show(struct device *dev, struct device_attribute *attr, char *buf)
{
<...
len =
- sprintf(buf,
+ sysfs_emit(buf,
...);
...>
return len;
}
@@
identifier d_show;
identifier dev, attr, buf;
identifier len;
@@
ssize_t d_show(struct device *dev, struct device_attribute *attr, char *buf)
{
<...
len =
- snprintf(buf, PAGE_SIZE,
+ sysfs_emit(buf,
...);
...>
return len;
}
@@
identifier d_show;
identifier dev, attr, buf;
identifier len;
@@
ssize_t d_show(struct device *dev, struct device_attribute *attr, char *buf)
{
<...
len =
- scnprintf(buf, PAGE_SIZE,
+ sysfs_emit(buf,
...);
...>
return len;
}
@@
identifier d_show;
identifier dev, attr, buf;
identifier len;
@@
ssize_t d_show(struct device *dev, struct device_attribute *attr, char *buf)
{
<...
- len += scnprintf(buf + len, PAGE_SIZE - len,
+ len += sysfs_emit_at(buf, len,
...);
...>
return len;
}
@@
identifier d_show;
identifier dev, attr, buf;
expression chr;
@@
ssize_t d_show(struct device *dev, struct device_attribute *attr, char *buf)
{
...
- strcpy(buf, chr);
- return strlen(buf);
+ return sysfs_emit(buf, chr);
}
Link: https://lore.kernel.org/r/7f406fa8e3aa2552c022bec680f621e38d1fe414.1602122879.git.joe@perches.com
Signed-off-by: Joe Perches <joe@perches.com>
Reviewed-by: Jason Gunthorpe <jgg@nvidia.com>
Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
2020-10-07 19:36:24 -07:00
return sysfs_emit ( page , " min-inflight (MI: %d) \n " ,
clt - > mp_policy ) ;
2021-04-07 13:34:41 +02:00
case MP_POLICY_MIN_LATENCY :
return sysfs_emit ( page , " min-latency (ML: %d) \n " ,
clt - > mp_policy ) ;
2020-05-11 15:51:14 +02:00
default :
RDMA: Convert sysfs device * show functions to use sysfs_emit()
Done with cocci script:
@@
identifier d_show;
identifier dev, attr, buf;
@@
ssize_t d_show(struct device *dev, struct device_attribute *attr, char *buf)
{
<...
return
- sprintf(buf,
+ sysfs_emit(buf,
...);
...>
}
@@
identifier d_show;
identifier dev, attr, buf;
@@
ssize_t d_show(struct device *dev, struct device_attribute *attr, char *buf)
{
<...
return
- snprintf(buf, PAGE_SIZE,
+ sysfs_emit(buf,
...);
...>
}
@@
identifier d_show;
identifier dev, attr, buf;
@@
ssize_t d_show(struct device *dev, struct device_attribute *attr, char *buf)
{
<...
return
- scnprintf(buf, PAGE_SIZE,
+ sysfs_emit(buf,
...);
...>
}
@@
identifier d_show;
identifier dev, attr, buf;
expression chr;
@@
ssize_t d_show(struct device *dev, struct device_attribute *attr, char *buf)
{
<...
return
- strcpy(buf, chr);
+ sysfs_emit(buf, chr);
...>
}
@@
identifier d_show;
identifier dev, attr, buf;
identifier len;
@@
ssize_t d_show(struct device *dev, struct device_attribute *attr, char *buf)
{
<...
len =
- sprintf(buf,
+ sysfs_emit(buf,
...);
...>
return len;
}
@@
identifier d_show;
identifier dev, attr, buf;
identifier len;
@@
ssize_t d_show(struct device *dev, struct device_attribute *attr, char *buf)
{
<...
len =
- snprintf(buf, PAGE_SIZE,
+ sysfs_emit(buf,
...);
...>
return len;
}
@@
identifier d_show;
identifier dev, attr, buf;
identifier len;
@@
ssize_t d_show(struct device *dev, struct device_attribute *attr, char *buf)
{
<...
len =
- scnprintf(buf, PAGE_SIZE,
+ sysfs_emit(buf,
...);
...>
return len;
}
@@
identifier d_show;
identifier dev, attr, buf;
identifier len;
@@
ssize_t d_show(struct device *dev, struct device_attribute *attr, char *buf)
{
<...
- len += scnprintf(buf + len, PAGE_SIZE - len,
+ len += sysfs_emit_at(buf, len,
...);
...>
return len;
}
@@
identifier d_show;
identifier dev, attr, buf;
expression chr;
@@
ssize_t d_show(struct device *dev, struct device_attribute *attr, char *buf)
{
...
- strcpy(buf, chr);
- return strlen(buf);
+ return sysfs_emit(buf, chr);
}
Link: https://lore.kernel.org/r/7f406fa8e3aa2552c022bec680f621e38d1fe414.1602122879.git.joe@perches.com
Signed-off-by: Joe Perches <joe@perches.com>
Reviewed-by: Jason Gunthorpe <jgg@nvidia.com>
Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
2020-10-07 19:36:24 -07:00
return sysfs_emit ( page , " Unknown (%d) \ n " , clt->mp_policy) ;
2020-05-11 15:51:14 +02:00
}
}
static ssize_t mpath_policy_store ( struct device * dev ,
struct device_attribute * attr ,
const char * buf ,
size_t count )
{
2022-01-05 19:07:08 +01:00
struct rtrs_clt_sess * clt ;
2020-05-11 15:51:14 +02:00
int value ;
int ret ;
2021-04-07 13:34:41 +02:00
size_t len = 0 ;
2020-05-11 15:51:14 +02:00
2022-01-05 19:07:08 +01:00
clt = container_of ( dev , struct rtrs_clt_sess , dev ) ;
2020-05-11 15:51:14 +02:00
ret = kstrtoint ( buf , 10 , & value ) ;
if ( ! ret & & ( value = = MP_POLICY_RR | |
2021-04-07 13:34:41 +02:00
value = = MP_POLICY_MIN_INFLIGHT | |
value = = MP_POLICY_MIN_LATENCY ) ) {
2020-05-11 15:51:14 +02:00
clt - > mp_policy = value ;
return count ;
}
2021-04-07 13:34:41 +02:00
/* distinguish "mi" and "min-latency" with length */
len = strnlen ( buf , NAME_MAX ) ;
if ( buf [ len - 1 ] = = ' \n ' )
len - - ;
2020-05-11 15:51:14 +02:00
if ( ! strncasecmp ( buf , " round-robin " , 11 ) | |
2021-04-07 13:34:41 +02:00
( len = = 2 & & ! strncasecmp ( buf , " rr " , 2 ) ) )
2020-05-11 15:51:14 +02:00
clt - > mp_policy = MP_POLICY_RR ;
else if ( ! strncasecmp ( buf , " min-inflight " , 12 ) | |
2021-04-07 13:34:41 +02:00
( len = = 2 & & ! strncasecmp ( buf , " mi " , 2 ) ) )
2020-05-11 15:51:14 +02:00
clt - > mp_policy = MP_POLICY_MIN_INFLIGHT ;
2021-04-07 13:34:41 +02:00
else if ( ! strncasecmp ( buf , " min-latency " , 11 ) | |
( len = = 2 & & ! strncasecmp ( buf , " ml " , 2 ) ) )
clt - > mp_policy = MP_POLICY_MIN_LATENCY ;
2020-05-11 15:51:14 +02:00
else
return - EINVAL ;
return count ;
}
static DEVICE_ATTR_RW ( mpath_policy ) ;
static ssize_t add_path_show ( struct device * dev ,
struct device_attribute * attr , char * page )
{
2022-01-14 16:47:51 +01:00
return sysfs_emit ( page ,
RDMA: Convert sysfs device * show functions to use sysfs_emit()
Done with cocci script:
@@
identifier d_show;
identifier dev, attr, buf;
@@
ssize_t d_show(struct device *dev, struct device_attribute *attr, char *buf)
{
<...
return
- sprintf(buf,
+ sysfs_emit(buf,
...);
...>
}
@@
identifier d_show;
identifier dev, attr, buf;
@@
ssize_t d_show(struct device *dev, struct device_attribute *attr, char *buf)
{
<...
return
- snprintf(buf, PAGE_SIZE,
+ sysfs_emit(buf,
...);
...>
}
@@
identifier d_show;
identifier dev, attr, buf;
@@
ssize_t d_show(struct device *dev, struct device_attribute *attr, char *buf)
{
<...
return
- scnprintf(buf, PAGE_SIZE,
+ sysfs_emit(buf,
...);
...>
}
@@
identifier d_show;
identifier dev, attr, buf;
expression chr;
@@
ssize_t d_show(struct device *dev, struct device_attribute *attr, char *buf)
{
<...
return
- strcpy(buf, chr);
+ sysfs_emit(buf, chr);
...>
}
@@
identifier d_show;
identifier dev, attr, buf;
identifier len;
@@
ssize_t d_show(struct device *dev, struct device_attribute *attr, char *buf)
{
<...
len =
- sprintf(buf,
+ sysfs_emit(buf,
...);
...>
return len;
}
@@
identifier d_show;
identifier dev, attr, buf;
identifier len;
@@
ssize_t d_show(struct device *dev, struct device_attribute *attr, char *buf)
{
<...
len =
- snprintf(buf, PAGE_SIZE,
+ sysfs_emit(buf,
...);
...>
return len;
}
@@
identifier d_show;
identifier dev, attr, buf;
identifier len;
@@
ssize_t d_show(struct device *dev, struct device_attribute *attr, char *buf)
{
<...
len =
- scnprintf(buf, PAGE_SIZE,
+ sysfs_emit(buf,
...);
...>
return len;
}
@@
identifier d_show;
identifier dev, attr, buf;
identifier len;
@@
ssize_t d_show(struct device *dev, struct device_attribute *attr, char *buf)
{
<...
- len += scnprintf(buf + len, PAGE_SIZE - len,
+ len += sysfs_emit_at(buf, len,
...);
...>
return len;
}
@@
identifier d_show;
identifier dev, attr, buf;
expression chr;
@@
ssize_t d_show(struct device *dev, struct device_attribute *attr, char *buf)
{
...
- strcpy(buf, chr);
- return strlen(buf);
+ return sysfs_emit(buf, chr);
}
Link: https://lore.kernel.org/r/7f406fa8e3aa2552c022bec680f621e38d1fe414.1602122879.git.joe@perches.com
Signed-off-by: Joe Perches <joe@perches.com>
Reviewed-by: Jason Gunthorpe <jgg@nvidia.com>
Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
2020-10-07 19:36:24 -07:00
" Usage: echo [<source addr>@]<destination addr> > %s \n \n *addr ::= [ ip:<ipv4|ipv6> | gid:<gid> ] \n " ,
attr - > attr . name ) ;
2020-05-11 15:51:14 +02:00
}
static ssize_t add_path_store ( struct device * dev ,
struct device_attribute * attr ,
const char * buf , size_t count )
{
struct sockaddr_storage srcaddr , dstaddr ;
struct rtrs_addr addr = {
. src = & srcaddr ,
. dst = & dstaddr
} ;
2022-01-05 19:07:08 +01:00
struct rtrs_clt_sess * clt ;
2020-05-11 15:51:14 +02:00
const char * nl ;
size_t len ;
int err ;
2022-01-05 19:07:08 +01:00
clt = container_of ( dev , struct rtrs_clt_sess , dev ) ;
2020-05-11 15:51:14 +02:00
nl = strchr ( buf , ' \n ' ) ;
if ( nl )
len = nl - buf ;
else
len = count ;
err = rtrs_addr_to_sockaddr ( buf , len , clt - > port , & addr ) ;
if ( err )
return - EINVAL ;
err = rtrs_clt_create_path_from_sysfs ( clt , & addr ) ;
if ( err )
return err ;
return count ;
}
static DEVICE_ATTR_RW ( add_path ) ;
static ssize_t rtrs_clt_state_show ( struct kobject * kobj ,
struct kobj_attribute * attr , char * page )
{
2022-01-05 19:07:06 +01:00
struct rtrs_clt_path * clt_path ;
2020-05-11 15:51:14 +02:00
2022-01-05 19:07:06 +01:00
clt_path = container_of ( kobj , struct rtrs_clt_path , kobj ) ;
if ( clt_path - > state = = RTRS_CLT_CONNECTED )
RDMA: Convert sysfs kobject * show functions to use sysfs_emit()
Done with cocci script:
@@
identifier k_show;
identifier arg1, arg2, arg3;
@@
ssize_t k_show(struct kobject *
- arg1
+ kobj
, struct kobj_attribute *
- arg2
+ attr
, char *
- arg3
+ buf
)
{
...
(
- arg1
+ kobj
|
- arg2
+ attr
|
- arg3
+ buf
)
...
}
@@
identifier k_show;
identifier kobj, attr, buf;
@@
ssize_t k_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf)
{
<...
return
- sprintf(buf,
+ sysfs_emit(buf,
...);
...>
}
@@
identifier k_show;
identifier kobj, attr, buf;
@@
ssize_t k_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf)
{
<...
return
- snprintf(buf, PAGE_SIZE,
+ sysfs_emit(buf,
...);
...>
}
@@
identifier k_show;
identifier kobj, attr, buf;
@@
ssize_t k_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf)
{
<...
return
- scnprintf(buf, PAGE_SIZE,
+ sysfs_emit(buf,
...);
...>
}
@@
identifier k_show;
identifier kobj, attr, buf;
expression chr;
@@
ssize_t k_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf)
{
<...
return
- strcpy(buf, chr);
+ sysfs_emit(buf, chr);
...>
}
@@
identifier k_show;
identifier kobj, attr, buf;
identifier len;
@@
ssize_t k_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf)
{
<...
len =
- sprintf(buf,
+ sysfs_emit(buf,
...);
...>
return len;
}
@@
identifier k_show;
identifier kobj, attr, buf;
identifier len;
@@
ssize_t k_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf)
{
<...
len =
- snprintf(buf, PAGE_SIZE,
+ sysfs_emit(buf,
...);
...>
return len;
}
@@
identifier k_show;
identifier kobj, attr, buf;
identifier len;
@@
ssize_t k_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf)
{
<...
len =
- scnprintf(buf, PAGE_SIZE,
+ sysfs_emit(buf,
...);
...>
return len;
}
@@
identifier k_show;
identifier kobj, attr, buf;
identifier len;
@@
ssize_t k_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf)
{
<...
- len += scnprintf(buf + len, PAGE_SIZE - len,
+ len += sysfs_emit_at(buf, len,
...);
...>
return len;
}
@@
identifier k_show;
identifier kobj, attr, buf;
expression chr;
@@
ssize_t k_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf)
{
...
- strcpy(buf, chr);
- return strlen(buf);
+ return sysfs_emit(buf, chr);
}
Link: https://lore.kernel.org/r/7761c1efaebb96c432c85171d58405c25a824ccd.1602122880.git.joe@perches.com
Signed-off-by: Joe Perches <joe@perches.com>
Reviewed-by: Jason Gunthorpe <jgg@nvidia.com>
Acked-by: Jack Wang <jinpu.wang@cloud.ionos.com>
Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
2020-10-07 19:36:25 -07:00
return sysfs_emit ( page , " connected \n " ) ;
2020-05-11 15:51:14 +02:00
RDMA: Convert sysfs kobject * show functions to use sysfs_emit()
Done with cocci script:
@@
identifier k_show;
identifier arg1, arg2, arg3;
@@
ssize_t k_show(struct kobject *
- arg1
+ kobj
, struct kobj_attribute *
- arg2
+ attr
, char *
- arg3
+ buf
)
{
...
(
- arg1
+ kobj
|
- arg2
+ attr
|
- arg3
+ buf
)
...
}
@@
identifier k_show;
identifier kobj, attr, buf;
@@
ssize_t k_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf)
{
<...
return
- sprintf(buf,
+ sysfs_emit(buf,
...);
...>
}
@@
identifier k_show;
identifier kobj, attr, buf;
@@
ssize_t k_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf)
{
<...
return
- snprintf(buf, PAGE_SIZE,
+ sysfs_emit(buf,
...);
...>
}
@@
identifier k_show;
identifier kobj, attr, buf;
@@
ssize_t k_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf)
{
<...
return
- scnprintf(buf, PAGE_SIZE,
+ sysfs_emit(buf,
...);
...>
}
@@
identifier k_show;
identifier kobj, attr, buf;
expression chr;
@@
ssize_t k_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf)
{
<...
return
- strcpy(buf, chr);
+ sysfs_emit(buf, chr);
...>
}
@@
identifier k_show;
identifier kobj, attr, buf;
identifier len;
@@
ssize_t k_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf)
{
<...
len =
- sprintf(buf,
+ sysfs_emit(buf,
...);
...>
return len;
}
@@
identifier k_show;
identifier kobj, attr, buf;
identifier len;
@@
ssize_t k_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf)
{
<...
len =
- snprintf(buf, PAGE_SIZE,
+ sysfs_emit(buf,
...);
...>
return len;
}
@@
identifier k_show;
identifier kobj, attr, buf;
identifier len;
@@
ssize_t k_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf)
{
<...
len =
- scnprintf(buf, PAGE_SIZE,
+ sysfs_emit(buf,
...);
...>
return len;
}
@@
identifier k_show;
identifier kobj, attr, buf;
identifier len;
@@
ssize_t k_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf)
{
<...
- len += scnprintf(buf + len, PAGE_SIZE - len,
+ len += sysfs_emit_at(buf, len,
...);
...>
return len;
}
@@
identifier k_show;
identifier kobj, attr, buf;
expression chr;
@@
ssize_t k_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf)
{
...
- strcpy(buf, chr);
- return strlen(buf);
+ return sysfs_emit(buf, chr);
}
Link: https://lore.kernel.org/r/7761c1efaebb96c432c85171d58405c25a824ccd.1602122880.git.joe@perches.com
Signed-off-by: Joe Perches <joe@perches.com>
Reviewed-by: Jason Gunthorpe <jgg@nvidia.com>
Acked-by: Jack Wang <jinpu.wang@cloud.ionos.com>
Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
2020-10-07 19:36:25 -07:00
return sysfs_emit ( page , " disconnected \n " ) ;
2020-05-11 15:51:14 +02:00
}
static struct kobj_attribute rtrs_clt_state_attr =
__ATTR ( state , 0444 , rtrs_clt_state_show , NULL ) ;
static ssize_t rtrs_clt_reconnect_show ( struct kobject * kobj ,
RDMA: Convert sysfs kobject * show functions to use sysfs_emit()
Done with cocci script:
@@
identifier k_show;
identifier arg1, arg2, arg3;
@@
ssize_t k_show(struct kobject *
- arg1
+ kobj
, struct kobj_attribute *
- arg2
+ attr
, char *
- arg3
+ buf
)
{
...
(
- arg1
+ kobj
|
- arg2
+ attr
|
- arg3
+ buf
)
...
}
@@
identifier k_show;
identifier kobj, attr, buf;
@@
ssize_t k_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf)
{
<...
return
- sprintf(buf,
+ sysfs_emit(buf,
...);
...>
}
@@
identifier k_show;
identifier kobj, attr, buf;
@@
ssize_t k_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf)
{
<...
return
- snprintf(buf, PAGE_SIZE,
+ sysfs_emit(buf,
...);
...>
}
@@
identifier k_show;
identifier kobj, attr, buf;
@@
ssize_t k_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf)
{
<...
return
- scnprintf(buf, PAGE_SIZE,
+ sysfs_emit(buf,
...);
...>
}
@@
identifier k_show;
identifier kobj, attr, buf;
expression chr;
@@
ssize_t k_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf)
{
<...
return
- strcpy(buf, chr);
+ sysfs_emit(buf, chr);
...>
}
@@
identifier k_show;
identifier kobj, attr, buf;
identifier len;
@@
ssize_t k_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf)
{
<...
len =
- sprintf(buf,
+ sysfs_emit(buf,
...);
...>
return len;
}
@@
identifier k_show;
identifier kobj, attr, buf;
identifier len;
@@
ssize_t k_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf)
{
<...
len =
- snprintf(buf, PAGE_SIZE,
+ sysfs_emit(buf,
...);
...>
return len;
}
@@
identifier k_show;
identifier kobj, attr, buf;
identifier len;
@@
ssize_t k_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf)
{
<...
len =
- scnprintf(buf, PAGE_SIZE,
+ sysfs_emit(buf,
...);
...>
return len;
}
@@
identifier k_show;
identifier kobj, attr, buf;
identifier len;
@@
ssize_t k_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf)
{
<...
- len += scnprintf(buf + len, PAGE_SIZE - len,
+ len += sysfs_emit_at(buf, len,
...);
...>
return len;
}
@@
identifier k_show;
identifier kobj, attr, buf;
expression chr;
@@
ssize_t k_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf)
{
...
- strcpy(buf, chr);
- return strlen(buf);
+ return sysfs_emit(buf, chr);
}
Link: https://lore.kernel.org/r/7761c1efaebb96c432c85171d58405c25a824ccd.1602122880.git.joe@perches.com
Signed-off-by: Joe Perches <joe@perches.com>
Reviewed-by: Jason Gunthorpe <jgg@nvidia.com>
Acked-by: Jack Wang <jinpu.wang@cloud.ionos.com>
Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
2020-10-07 19:36:25 -07:00
struct kobj_attribute * attr , char * buf )
2020-05-11 15:51:14 +02:00
{
RDMA: Convert sysfs kobject * show functions to use sysfs_emit()
Done with cocci script:
@@
identifier k_show;
identifier arg1, arg2, arg3;
@@
ssize_t k_show(struct kobject *
- arg1
+ kobj
, struct kobj_attribute *
- arg2
+ attr
, char *
- arg3
+ buf
)
{
...
(
- arg1
+ kobj
|
- arg2
+ attr
|
- arg3
+ buf
)
...
}
@@
identifier k_show;
identifier kobj, attr, buf;
@@
ssize_t k_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf)
{
<...
return
- sprintf(buf,
+ sysfs_emit(buf,
...);
...>
}
@@
identifier k_show;
identifier kobj, attr, buf;
@@
ssize_t k_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf)
{
<...
return
- snprintf(buf, PAGE_SIZE,
+ sysfs_emit(buf,
...);
...>
}
@@
identifier k_show;
identifier kobj, attr, buf;
@@
ssize_t k_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf)
{
<...
return
- scnprintf(buf, PAGE_SIZE,
+ sysfs_emit(buf,
...);
...>
}
@@
identifier k_show;
identifier kobj, attr, buf;
expression chr;
@@
ssize_t k_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf)
{
<...
return
- strcpy(buf, chr);
+ sysfs_emit(buf, chr);
...>
}
@@
identifier k_show;
identifier kobj, attr, buf;
identifier len;
@@
ssize_t k_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf)
{
<...
len =
- sprintf(buf,
+ sysfs_emit(buf,
...);
...>
return len;
}
@@
identifier k_show;
identifier kobj, attr, buf;
identifier len;
@@
ssize_t k_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf)
{
<...
len =
- snprintf(buf, PAGE_SIZE,
+ sysfs_emit(buf,
...);
...>
return len;
}
@@
identifier k_show;
identifier kobj, attr, buf;
identifier len;
@@
ssize_t k_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf)
{
<...
len =
- scnprintf(buf, PAGE_SIZE,
+ sysfs_emit(buf,
...);
...>
return len;
}
@@
identifier k_show;
identifier kobj, attr, buf;
identifier len;
@@
ssize_t k_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf)
{
<...
- len += scnprintf(buf + len, PAGE_SIZE - len,
+ len += sysfs_emit_at(buf, len,
...);
...>
return len;
}
@@
identifier k_show;
identifier kobj, attr, buf;
expression chr;
@@
ssize_t k_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf)
{
...
- strcpy(buf, chr);
- return strlen(buf);
+ return sysfs_emit(buf, chr);
}
Link: https://lore.kernel.org/r/7761c1efaebb96c432c85171d58405c25a824ccd.1602122880.git.joe@perches.com
Signed-off-by: Joe Perches <joe@perches.com>
Reviewed-by: Jason Gunthorpe <jgg@nvidia.com>
Acked-by: Jack Wang <jinpu.wang@cloud.ionos.com>
Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
2020-10-07 19:36:25 -07:00
return sysfs_emit ( buf , " Usage: echo 1 > %s \n " , attr - > attr . name ) ;
2020-05-11 15:51:14 +02:00
}
static ssize_t rtrs_clt_reconnect_store ( struct kobject * kobj ,
struct kobj_attribute * attr ,
const char * buf , size_t count )
{
2022-01-05 19:07:06 +01:00
struct rtrs_clt_path * clt_path ;
2020-05-11 15:51:14 +02:00
int ret ;
2022-01-05 19:07:06 +01:00
clt_path = container_of ( kobj , struct rtrs_clt_path , kobj ) ;
2020-05-11 15:51:14 +02:00
if ( ! sysfs_streq ( buf , " 1 " ) ) {
2022-01-05 19:07:06 +01:00
rtrs_err ( clt_path - > clt , " %s: unknown value: '%s' \n " ,
2020-05-11 15:51:14 +02:00
attr - > attr . name , buf ) ;
return - EINVAL ;
}
2022-01-05 19:07:06 +01:00
ret = rtrs_clt_reconnect_from_sysfs ( clt_path ) ;
2020-05-11 15:51:14 +02:00
if ( ret )
return ret ;
return count ;
}
static struct kobj_attribute rtrs_clt_reconnect_attr =
__ATTR ( reconnect , 0644 , rtrs_clt_reconnect_show ,
rtrs_clt_reconnect_store ) ;
static ssize_t rtrs_clt_disconnect_show ( struct kobject * kobj ,
RDMA: Convert sysfs kobject * show functions to use sysfs_emit()
Done with cocci script:
@@
identifier k_show;
identifier arg1, arg2, arg3;
@@
ssize_t k_show(struct kobject *
- arg1
+ kobj
, struct kobj_attribute *
- arg2
+ attr
, char *
- arg3
+ buf
)
{
...
(
- arg1
+ kobj
|
- arg2
+ attr
|
- arg3
+ buf
)
...
}
@@
identifier k_show;
identifier kobj, attr, buf;
@@
ssize_t k_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf)
{
<...
return
- sprintf(buf,
+ sysfs_emit(buf,
...);
...>
}
@@
identifier k_show;
identifier kobj, attr, buf;
@@
ssize_t k_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf)
{
<...
return
- snprintf(buf, PAGE_SIZE,
+ sysfs_emit(buf,
...);
...>
}
@@
identifier k_show;
identifier kobj, attr, buf;
@@
ssize_t k_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf)
{
<...
return
- scnprintf(buf, PAGE_SIZE,
+ sysfs_emit(buf,
...);
...>
}
@@
identifier k_show;
identifier kobj, attr, buf;
expression chr;
@@
ssize_t k_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf)
{
<...
return
- strcpy(buf, chr);
+ sysfs_emit(buf, chr);
...>
}
@@
identifier k_show;
identifier kobj, attr, buf;
identifier len;
@@
ssize_t k_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf)
{
<...
len =
- sprintf(buf,
+ sysfs_emit(buf,
...);
...>
return len;
}
@@
identifier k_show;
identifier kobj, attr, buf;
identifier len;
@@
ssize_t k_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf)
{
<...
len =
- snprintf(buf, PAGE_SIZE,
+ sysfs_emit(buf,
...);
...>
return len;
}
@@
identifier k_show;
identifier kobj, attr, buf;
identifier len;
@@
ssize_t k_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf)
{
<...
len =
- scnprintf(buf, PAGE_SIZE,
+ sysfs_emit(buf,
...);
...>
return len;
}
@@
identifier k_show;
identifier kobj, attr, buf;
identifier len;
@@
ssize_t k_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf)
{
<...
- len += scnprintf(buf + len, PAGE_SIZE - len,
+ len += sysfs_emit_at(buf, len,
...);
...>
return len;
}
@@
identifier k_show;
identifier kobj, attr, buf;
expression chr;
@@
ssize_t k_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf)
{
...
- strcpy(buf, chr);
- return strlen(buf);
+ return sysfs_emit(buf, chr);
}
Link: https://lore.kernel.org/r/7761c1efaebb96c432c85171d58405c25a824ccd.1602122880.git.joe@perches.com
Signed-off-by: Joe Perches <joe@perches.com>
Reviewed-by: Jason Gunthorpe <jgg@nvidia.com>
Acked-by: Jack Wang <jinpu.wang@cloud.ionos.com>
Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
2020-10-07 19:36:25 -07:00
struct kobj_attribute * attr , char * buf )
2020-05-11 15:51:14 +02:00
{
RDMA: Convert sysfs kobject * show functions to use sysfs_emit()
Done with cocci script:
@@
identifier k_show;
identifier arg1, arg2, arg3;
@@
ssize_t k_show(struct kobject *
- arg1
+ kobj
, struct kobj_attribute *
- arg2
+ attr
, char *
- arg3
+ buf
)
{
...
(
- arg1
+ kobj
|
- arg2
+ attr
|
- arg3
+ buf
)
...
}
@@
identifier k_show;
identifier kobj, attr, buf;
@@
ssize_t k_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf)
{
<...
return
- sprintf(buf,
+ sysfs_emit(buf,
...);
...>
}
@@
identifier k_show;
identifier kobj, attr, buf;
@@
ssize_t k_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf)
{
<...
return
- snprintf(buf, PAGE_SIZE,
+ sysfs_emit(buf,
...);
...>
}
@@
identifier k_show;
identifier kobj, attr, buf;
@@
ssize_t k_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf)
{
<...
return
- scnprintf(buf, PAGE_SIZE,
+ sysfs_emit(buf,
...);
...>
}
@@
identifier k_show;
identifier kobj, attr, buf;
expression chr;
@@
ssize_t k_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf)
{
<...
return
- strcpy(buf, chr);
+ sysfs_emit(buf, chr);
...>
}
@@
identifier k_show;
identifier kobj, attr, buf;
identifier len;
@@
ssize_t k_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf)
{
<...
len =
- sprintf(buf,
+ sysfs_emit(buf,
...);
...>
return len;
}
@@
identifier k_show;
identifier kobj, attr, buf;
identifier len;
@@
ssize_t k_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf)
{
<...
len =
- snprintf(buf, PAGE_SIZE,
+ sysfs_emit(buf,
...);
...>
return len;
}
@@
identifier k_show;
identifier kobj, attr, buf;
identifier len;
@@
ssize_t k_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf)
{
<...
len =
- scnprintf(buf, PAGE_SIZE,
+ sysfs_emit(buf,
...);
...>
return len;
}
@@
identifier k_show;
identifier kobj, attr, buf;
identifier len;
@@
ssize_t k_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf)
{
<...
- len += scnprintf(buf + len, PAGE_SIZE - len,
+ len += sysfs_emit_at(buf, len,
...);
...>
return len;
}
@@
identifier k_show;
identifier kobj, attr, buf;
expression chr;
@@
ssize_t k_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf)
{
...
- strcpy(buf, chr);
- return strlen(buf);
+ return sysfs_emit(buf, chr);
}
Link: https://lore.kernel.org/r/7761c1efaebb96c432c85171d58405c25a824ccd.1602122880.git.joe@perches.com
Signed-off-by: Joe Perches <joe@perches.com>
Reviewed-by: Jason Gunthorpe <jgg@nvidia.com>
Acked-by: Jack Wang <jinpu.wang@cloud.ionos.com>
Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
2020-10-07 19:36:25 -07:00
return sysfs_emit ( buf , " Usage: echo 1 > %s \n " , attr - > attr . name ) ;
2020-05-11 15:51:14 +02:00
}
static ssize_t rtrs_clt_disconnect_store ( struct kobject * kobj ,
struct kobj_attribute * attr ,
const char * buf , size_t count )
{
2022-01-05 19:07:06 +01:00
struct rtrs_clt_path * clt_path ;
2020-05-11 15:51:14 +02:00
2022-01-05 19:07:06 +01:00
clt_path = container_of ( kobj , struct rtrs_clt_path , kobj ) ;
2020-05-11 15:51:14 +02:00
if ( ! sysfs_streq ( buf , " 1 " ) ) {
2022-01-05 19:07:06 +01:00
rtrs_err ( clt_path - > clt , " %s: unknown value: '%s' \n " ,
2020-05-11 15:51:14 +02:00
attr - > attr . name , buf ) ;
return - EINVAL ;
}
2022-01-05 19:07:06 +01:00
rtrs_clt_close_conns ( clt_path , true ) ;
2020-05-11 15:51:14 +02:00
return count ;
}
static struct kobj_attribute rtrs_clt_disconnect_attr =
__ATTR ( disconnect , 0644 , rtrs_clt_disconnect_show ,
rtrs_clt_disconnect_store ) ;
static ssize_t rtrs_clt_remove_path_show ( struct kobject * kobj ,
RDMA: Convert sysfs kobject * show functions to use sysfs_emit()
Done with cocci script:
@@
identifier k_show;
identifier arg1, arg2, arg3;
@@
ssize_t k_show(struct kobject *
- arg1
+ kobj
, struct kobj_attribute *
- arg2
+ attr
, char *
- arg3
+ buf
)
{
...
(
- arg1
+ kobj
|
- arg2
+ attr
|
- arg3
+ buf
)
...
}
@@
identifier k_show;
identifier kobj, attr, buf;
@@
ssize_t k_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf)
{
<...
return
- sprintf(buf,
+ sysfs_emit(buf,
...);
...>
}
@@
identifier k_show;
identifier kobj, attr, buf;
@@
ssize_t k_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf)
{
<...
return
- snprintf(buf, PAGE_SIZE,
+ sysfs_emit(buf,
...);
...>
}
@@
identifier k_show;
identifier kobj, attr, buf;
@@
ssize_t k_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf)
{
<...
return
- scnprintf(buf, PAGE_SIZE,
+ sysfs_emit(buf,
...);
...>
}
@@
identifier k_show;
identifier kobj, attr, buf;
expression chr;
@@
ssize_t k_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf)
{
<...
return
- strcpy(buf, chr);
+ sysfs_emit(buf, chr);
...>
}
@@
identifier k_show;
identifier kobj, attr, buf;
identifier len;
@@
ssize_t k_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf)
{
<...
len =
- sprintf(buf,
+ sysfs_emit(buf,
...);
...>
return len;
}
@@
identifier k_show;
identifier kobj, attr, buf;
identifier len;
@@
ssize_t k_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf)
{
<...
len =
- snprintf(buf, PAGE_SIZE,
+ sysfs_emit(buf,
...);
...>
return len;
}
@@
identifier k_show;
identifier kobj, attr, buf;
identifier len;
@@
ssize_t k_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf)
{
<...
len =
- scnprintf(buf, PAGE_SIZE,
+ sysfs_emit(buf,
...);
...>
return len;
}
@@
identifier k_show;
identifier kobj, attr, buf;
identifier len;
@@
ssize_t k_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf)
{
<...
- len += scnprintf(buf + len, PAGE_SIZE - len,
+ len += sysfs_emit_at(buf, len,
...);
...>
return len;
}
@@
identifier k_show;
identifier kobj, attr, buf;
expression chr;
@@
ssize_t k_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf)
{
...
- strcpy(buf, chr);
- return strlen(buf);
+ return sysfs_emit(buf, chr);
}
Link: https://lore.kernel.org/r/7761c1efaebb96c432c85171d58405c25a824ccd.1602122880.git.joe@perches.com
Signed-off-by: Joe Perches <joe@perches.com>
Reviewed-by: Jason Gunthorpe <jgg@nvidia.com>
Acked-by: Jack Wang <jinpu.wang@cloud.ionos.com>
Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
2020-10-07 19:36:25 -07:00
struct kobj_attribute * attr , char * buf )
2020-05-11 15:51:14 +02:00
{
RDMA: Convert sysfs kobject * show functions to use sysfs_emit()
Done with cocci script:
@@
identifier k_show;
identifier arg1, arg2, arg3;
@@
ssize_t k_show(struct kobject *
- arg1
+ kobj
, struct kobj_attribute *
- arg2
+ attr
, char *
- arg3
+ buf
)
{
...
(
- arg1
+ kobj
|
- arg2
+ attr
|
- arg3
+ buf
)
...
}
@@
identifier k_show;
identifier kobj, attr, buf;
@@
ssize_t k_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf)
{
<...
return
- sprintf(buf,
+ sysfs_emit(buf,
...);
...>
}
@@
identifier k_show;
identifier kobj, attr, buf;
@@
ssize_t k_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf)
{
<...
return
- snprintf(buf, PAGE_SIZE,
+ sysfs_emit(buf,
...);
...>
}
@@
identifier k_show;
identifier kobj, attr, buf;
@@
ssize_t k_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf)
{
<...
return
- scnprintf(buf, PAGE_SIZE,
+ sysfs_emit(buf,
...);
...>
}
@@
identifier k_show;
identifier kobj, attr, buf;
expression chr;
@@
ssize_t k_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf)
{
<...
return
- strcpy(buf, chr);
+ sysfs_emit(buf, chr);
...>
}
@@
identifier k_show;
identifier kobj, attr, buf;
identifier len;
@@
ssize_t k_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf)
{
<...
len =
- sprintf(buf,
+ sysfs_emit(buf,
...);
...>
return len;
}
@@
identifier k_show;
identifier kobj, attr, buf;
identifier len;
@@
ssize_t k_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf)
{
<...
len =
- snprintf(buf, PAGE_SIZE,
+ sysfs_emit(buf,
...);
...>
return len;
}
@@
identifier k_show;
identifier kobj, attr, buf;
identifier len;
@@
ssize_t k_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf)
{
<...
len =
- scnprintf(buf, PAGE_SIZE,
+ sysfs_emit(buf,
...);
...>
return len;
}
@@
identifier k_show;
identifier kobj, attr, buf;
identifier len;
@@
ssize_t k_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf)
{
<...
- len += scnprintf(buf + len, PAGE_SIZE - len,
+ len += sysfs_emit_at(buf, len,
...);
...>
return len;
}
@@
identifier k_show;
identifier kobj, attr, buf;
expression chr;
@@
ssize_t k_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf)
{
...
- strcpy(buf, chr);
- return strlen(buf);
+ return sysfs_emit(buf, chr);
}
Link: https://lore.kernel.org/r/7761c1efaebb96c432c85171d58405c25a824ccd.1602122880.git.joe@perches.com
Signed-off-by: Joe Perches <joe@perches.com>
Reviewed-by: Jason Gunthorpe <jgg@nvidia.com>
Acked-by: Jack Wang <jinpu.wang@cloud.ionos.com>
Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
2020-10-07 19:36:25 -07:00
return sysfs_emit ( buf , " Usage: echo 1 > %s \n " , attr - > attr . name ) ;
2020-05-11 15:51:14 +02:00
}
static ssize_t rtrs_clt_remove_path_store ( struct kobject * kobj ,
struct kobj_attribute * attr ,
const char * buf , size_t count )
{
2022-01-05 19:07:06 +01:00
struct rtrs_clt_path * clt_path ;
2020-05-11 15:51:14 +02:00
int ret ;
2022-01-05 19:07:06 +01:00
clt_path = container_of ( kobj , struct rtrs_clt_path , kobj ) ;
2020-05-11 15:51:14 +02:00
if ( ! sysfs_streq ( buf , " 1 " ) ) {
2022-01-05 19:07:06 +01:00
rtrs_err ( clt_path - > clt , " %s: unknown value: '%s' \n " ,
2020-05-11 15:51:14 +02:00
attr - > attr . name , buf ) ;
return - EINVAL ;
}
2022-01-05 19:07:06 +01:00
ret = rtrs_clt_remove_path_from_sysfs ( clt_path , & attr - > attr ) ;
2020-05-11 15:51:14 +02:00
if ( ret )
return ret ;
return count ;
}
static struct kobj_attribute rtrs_clt_remove_path_attr =
__ATTR ( remove_path , 0644 , rtrs_clt_remove_path_show ,
rtrs_clt_remove_path_store ) ;
2021-09-22 14:53:33 +02:00
STAT_ATTR ( struct rtrs_clt_stats , cpu_migration_from ,
rtrs_clt_stats_migration_from_cnt_to_str ,
rtrs_clt_reset_cpu_migr_stats ) ;
STAT_ATTR ( struct rtrs_clt_stats , cpu_migration_to ,
rtrs_clt_stats_migration_to_cnt_to_str ,
2020-05-11 15:51:14 +02:00
rtrs_clt_reset_cpu_migr_stats ) ;
STAT_ATTR ( struct rtrs_clt_stats , reconnects ,
rtrs_clt_stats_reconnects_to_str ,
rtrs_clt_reset_reconnects_stat ) ;
STAT_ATTR ( struct rtrs_clt_stats , rdma ,
rtrs_clt_stats_rdma_to_str ,
rtrs_clt_reset_rdma_stats ) ;
STAT_ATTR ( struct rtrs_clt_stats , reset_all ,
rtrs_clt_reset_all_help ,
rtrs_clt_reset_all_stats ) ;
static struct attribute * rtrs_clt_stats_attrs [ ] = {
2021-09-22 14:53:33 +02:00
& cpu_migration_from_attr . attr ,
& cpu_migration_to_attr . attr ,
2020-05-11 15:51:14 +02:00
& reconnects_attr . attr ,
& rdma_attr . attr ,
& reset_all_attr . attr ,
NULL
} ;
2020-10-01 00:40:04 +02:00
static const struct attribute_group rtrs_clt_stats_attr_group = {
2020-05-11 15:51:14 +02:00
. attrs = rtrs_clt_stats_attrs ,
} ;
static ssize_t rtrs_clt_hca_port_show ( struct kobject * kobj ,
struct kobj_attribute * attr ,
char * page )
{
2022-01-05 19:07:06 +01:00
struct rtrs_clt_path * clt_path ;
2020-05-11 15:51:14 +02:00
2022-01-05 19:07:06 +01:00
clt_path = container_of ( kobj , typeof ( * clt_path ) , kobj ) ;
2020-05-11 15:51:14 +02:00
2022-01-05 19:07:06 +01:00
return sysfs_emit ( page , " %u \n " , clt_path - > hca_port ) ;
2020-05-11 15:51:14 +02:00
}
static struct kobj_attribute rtrs_clt_hca_port_attr =
__ATTR ( hca_port , 0444 , rtrs_clt_hca_port_show , NULL ) ;
static ssize_t rtrs_clt_hca_name_show ( struct kobject * kobj ,
struct kobj_attribute * attr ,
char * page )
{
2022-01-05 19:07:06 +01:00
struct rtrs_clt_path * clt_path ;
2020-05-11 15:51:14 +02:00
2022-01-05 19:07:06 +01:00
clt_path = container_of ( kobj , struct rtrs_clt_path , kobj ) ;
2020-05-11 15:51:14 +02:00
2022-01-05 19:07:06 +01:00
return sysfs_emit ( page , " %s \n " , clt_path - > hca_name ) ;
2020-05-11 15:51:14 +02:00
}
static struct kobj_attribute rtrs_clt_hca_name_attr =
__ATTR ( hca_name , 0444 , rtrs_clt_hca_name_show , NULL ) ;
2021-04-07 13:34:42 +02:00
static ssize_t rtrs_clt_cur_latency_show ( struct kobject * kobj ,
struct kobj_attribute * attr ,
char * page )
{
2022-01-05 19:07:06 +01:00
struct rtrs_clt_path * clt_path ;
2021-04-07 13:34:42 +02:00
2022-01-05 19:07:06 +01:00
clt_path = container_of ( kobj , struct rtrs_clt_path , kobj ) ;
2021-04-07 13:34:42 +02:00
return sysfs_emit ( page , " %lld ns \n " ,
2022-01-05 19:07:06 +01:00
ktime_to_ns ( clt_path - > s . hb_cur_latency ) ) ;
2021-04-07 13:34:42 +02:00
}
static struct kobj_attribute rtrs_clt_cur_latency_attr =
__ATTR ( cur_latency , 0444 , rtrs_clt_cur_latency_show , NULL ) ;
2020-05-11 15:51:14 +02:00
static ssize_t rtrs_clt_src_addr_show ( struct kobject * kobj ,
struct kobj_attribute * attr ,
char * page )
{
2022-01-05 19:07:06 +01:00
struct rtrs_clt_path * clt_path ;
2020-10-07 19:36:27 -07:00
int len ;
2020-05-11 15:51:14 +02:00
2022-01-05 19:07:06 +01:00
clt_path = container_of ( kobj , struct rtrs_clt_path , kobj ) ;
len = sockaddr_to_str ( ( struct sockaddr * ) & clt_path - > s . src_addr , page ,
2020-10-07 19:36:27 -07:00
PAGE_SIZE ) ;
len + = sysfs_emit_at ( page , len , " \n " ) ;
return len ;
2020-05-11 15:51:14 +02:00
}
static struct kobj_attribute rtrs_clt_src_addr_attr =
__ATTR ( src_addr , 0444 , rtrs_clt_src_addr_show , NULL ) ;
static ssize_t rtrs_clt_dst_addr_show ( struct kobject * kobj ,
struct kobj_attribute * attr ,
char * page )
{
2022-01-05 19:07:06 +01:00
struct rtrs_clt_path * clt_path ;
2020-10-07 19:36:27 -07:00
int len ;
2020-05-11 15:51:14 +02:00
2022-01-05 19:07:06 +01:00
clt_path = container_of ( kobj , struct rtrs_clt_path , kobj ) ;
len = sockaddr_to_str ( ( struct sockaddr * ) & clt_path - > s . dst_addr , page ,
2020-10-07 19:36:27 -07:00
PAGE_SIZE ) ;
len + = sysfs_emit_at ( page , len , " \n " ) ;
return len ;
2020-05-11 15:51:14 +02:00
}
static struct kobj_attribute rtrs_clt_dst_addr_attr =
__ATTR ( dst_addr , 0444 , rtrs_clt_dst_addr_show , NULL ) ;
2022-01-05 19:07:06 +01:00
static struct attribute * rtrs_clt_path_attrs [ ] = {
2020-05-11 15:51:14 +02:00
& rtrs_clt_hca_name_attr . attr ,
& rtrs_clt_hca_port_attr . attr ,
& rtrs_clt_src_addr_attr . attr ,
& rtrs_clt_dst_addr_attr . attr ,
& rtrs_clt_state_attr . attr ,
& rtrs_clt_reconnect_attr . attr ,
& rtrs_clt_disconnect_attr . attr ,
& rtrs_clt_remove_path_attr . attr ,
2021-04-07 13:34:42 +02:00
& rtrs_clt_cur_latency_attr . attr ,
2020-05-11 15:51:14 +02:00
NULL ,
} ;
2022-01-05 19:07:06 +01:00
static const struct attribute_group rtrs_clt_path_attr_group = {
. attrs = rtrs_clt_path_attrs ,
2020-05-11 15:51:14 +02:00
} ;
2022-01-05 19:07:06 +01:00
int rtrs_clt_create_path_files ( struct rtrs_clt_path * clt_path )
2020-05-11 15:51:14 +02:00
{
2022-01-05 19:07:08 +01:00
struct rtrs_clt_sess * clt = clt_path - > clt ;
2020-05-11 15:51:14 +02:00
char str [ NAME_MAX ] ;
2021-03-25 16:32:59 +01:00
int err ;
struct rtrs_addr path = {
2022-01-05 19:07:06 +01:00
. src = & clt_path - > s . src_addr ,
. dst = & clt_path - > s . dst_addr ,
2021-03-25 16:32:59 +01:00
} ;
2020-05-11 15:51:14 +02:00
2021-03-25 16:32:59 +01:00
rtrs_addr_to_str ( & path , str , sizeof ( str ) ) ;
2022-01-05 19:07:06 +01:00
err = kobject_init_and_add ( & clt_path - > kobj , & ktype_sess ,
clt - > kobj_paths ,
2020-05-11 15:51:14 +02:00
" %s " , str ) ;
if ( err ) {
pr_err ( " kobject_init_and_add: %d \n " , err ) ;
2022-01-05 19:07:06 +01:00
kobject_put ( & clt_path - > kobj ) ;
2020-05-11 15:51:14 +02:00
return err ;
}
2022-01-05 19:07:06 +01:00
err = sysfs_create_group ( & clt_path - > kobj , & rtrs_clt_path_attr_group ) ;
2020-05-11 15:51:14 +02:00
if ( err ) {
pr_err ( " sysfs_create_group(): %d \n " , err ) ;
goto put_kobj ;
}
2022-01-05 19:07:06 +01:00
err = kobject_init_and_add ( & clt_path - > stats - > kobj_stats , & ktype_stats ,
& clt_path - > kobj , " stats " ) ;
2020-05-11 15:51:14 +02:00
if ( err ) {
pr_err ( " kobject_init_and_add: %d \n " , err ) ;
2022-01-05 19:07:06 +01:00
kobject_put ( & clt_path - > stats - > kobj_stats ) ;
2020-05-11 15:51:14 +02:00
goto remove_group ;
}
2022-01-05 19:07:06 +01:00
err = sysfs_create_group ( & clt_path - > stats - > kobj_stats ,
2020-05-11 15:51:14 +02:00
& rtrs_clt_stats_attr_group ) ;
if ( err ) {
pr_err ( " failed to create stats sysfs group, err: %d \n " , err ) ;
goto put_kobj_stats ;
}
return 0 ;
put_kobj_stats :
2022-01-05 19:07:06 +01:00
kobject_del ( & clt_path - > stats - > kobj_stats ) ;
kobject_put ( & clt_path - > stats - > kobj_stats ) ;
2020-05-11 15:51:14 +02:00
remove_group :
2022-01-05 19:07:06 +01:00
sysfs_remove_group ( & clt_path - > kobj , & rtrs_clt_path_attr_group ) ;
2020-05-11 15:51:14 +02:00
put_kobj :
2022-01-05 19:07:06 +01:00
kobject_del ( & clt_path - > kobj ) ;
kobject_put ( & clt_path - > kobj ) ;
2020-05-11 15:51:14 +02:00
return err ;
}
2022-01-05 19:07:06 +01:00
void rtrs_clt_destroy_path_files ( struct rtrs_clt_path * clt_path ,
2020-05-11 15:51:14 +02:00
const struct attribute * sysfs_self )
{
2022-01-05 19:07:06 +01:00
kobject_del ( & clt_path - > stats - > kobj_stats ) ;
kobject_put ( & clt_path - > stats - > kobj_stats ) ;
2020-05-11 15:51:14 +02:00
if ( sysfs_self )
2022-01-05 19:07:06 +01:00
sysfs_remove_file_self ( & clt_path - > kobj , sysfs_self ) ;
kobject_del ( & clt_path - > kobj ) ;
2020-05-11 15:51:14 +02:00
}
static struct attribute * rtrs_clt_attrs [ ] = {
& dev_attr_max_reconnect_attempts . attr ,
& dev_attr_mpath_policy . attr ,
& dev_attr_add_path . attr ,
NULL ,
} ;
2020-10-01 00:40:04 +02:00
static const struct attribute_group rtrs_clt_attr_group = {
2020-05-11 15:51:14 +02:00
. attrs = rtrs_clt_attrs ,
} ;
2022-01-05 19:07:08 +01:00
int rtrs_clt_create_sysfs_root_files ( struct rtrs_clt_sess * clt )
2020-05-11 15:51:14 +02:00
{
return sysfs_create_group ( & clt - > dev . kobj , & rtrs_clt_attr_group ) ;
}
2022-01-05 19:07:08 +01:00
void rtrs_clt_destroy_sysfs_root ( struct rtrs_clt_sess * clt )
2020-05-11 15:51:14 +02:00
{
2020-12-17 15:19:04 +01:00
sysfs_remove_group ( & clt - > dev . kobj , & rtrs_clt_attr_group ) ;
2020-05-11 15:51:14 +02:00
if ( clt - > kobj_paths ) {
kobject_del ( clt - > kobj_paths ) ;
kobject_put ( clt - > kobj_paths ) ;
}
}