summary |
shortlog |
log |
commit | commitdiff |
tree
raw |
patch |
inline | side by side (from parent 1:
49acd14)
Remove an unnecessary counter and move the comment before
the relevant code. Improve error messages.
Test-parameters: trivial
Signed-off-by: Olaf Faaland <faaland1@llnl.gov>
Change-Id: Iffc7a128b16bc1b2be7a44413a5972c97b12a5fa
Reviewed-on: https://review.whamcloud.com/43525
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: Serguei Smirnov <ssmirnov@whamcloud.com>
Reviewed-by: Neil Brown <neilb@suse.de>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
static int
lnet_ni_add_interface(struct lnet_ni *ni, char *iface)
{
static int
lnet_ni_add_interface(struct lnet_ni *ni, char *iface)
{
+ size_t iface_len = strlen(iface) + 1;
if (ni == NULL)
return -ENOMEM;
if (ni == NULL)
return -ENOMEM;
- /* Allocate a separate piece of memory and copy
- * into it the string, so we don't have
- * a depencency on the tokens string. This way we
- * can free the tokens at the end of the function.
- * The newly allocated ni_interface can be
- * freed when freeing the NI */
- if (ni->ni_interface != NULL)
- niface++;
-
- if (niface >= 1) {
- LCONSOLE_ERROR_MSG(0x115, "Too many interfaces "
- "for net %s\n",
- libcfs_net2str(LNET_NIDNET(ni->ni_nid)));
+ if (ni->ni_interface != NULL) {
+ LCONSOLE_ERROR_MSG(0x115, "%s: interface %s already set for net %s: rc = %d\n",
+ iface, ni->ni_interface,
+ libcfs_net2str(LNET_NIDNET(ni->ni_nid)),
+ -EINVAL);
- LIBCFS_ALLOC(ni->ni_interface,
- strlen(iface) + 1);
+ /* Allocate memory for the interface, so the code parsing input into
+ * tokens and adding interfaces can free the input safely.
+ * ni->ni_interface is freed in lnet_ni_free().
+ */
+ LIBCFS_ALLOC(ni->ni_interface, iface_len);
if (ni->ni_interface == NULL) {
if (ni->ni_interface == NULL) {
- CERROR("Can't allocate net interface name\n");
+ CERROR("%s: cannot allocate net interface name: rc = %d\n",
+ iface, -ENOMEM);
- strncpy(ni->ni_interface, iface,
- strlen(iface) + 1);
+ strscpy(ni->ni_interface, iface, iface_len);