summaryrefslogtreecommitdiff
path: root/drivers/scsi/libfc
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/scsi/libfc')
-rw-r--r--drivers/scsi/libfc/fc_encode.h30
1 files changed, 19 insertions, 11 deletions
diff --git a/drivers/scsi/libfc/fc_encode.h b/drivers/scsi/libfc/fc_encode.h
index 18203cae04b2..602c97a651bc 100644
--- a/drivers/scsi/libfc/fc_encode.h
+++ b/drivers/scsi/libfc/fc_encode.h
@@ -163,6 +163,14 @@ static inline int fc_ct_ns_fill(struct fc_lport *lport,
return 0;
}
+static inline void fc_ct_ms_fill_attr(struct fc_fdmi_attr_entry *entry,
+ const char *in, size_t len)
+{
+ int copied = strscpy(entry->value, in, len);
+ if (copied > 0)
+ memset(entry->value, copied, len - copied);
+}
+
/**
* fc_ct_ms_fill() - Fill in a mgmt service request frame
* @lport: local port.
@@ -232,7 +240,7 @@ static inline int fc_ct_ms_fill(struct fc_lport *lport,
put_unaligned_be16(FC_FDMI_HBA_ATTR_MANUFACTURER,
&entry->type);
put_unaligned_be16(len, &entry->len);
- strncpy((char *)&entry->value,
+ fc_ct_ms_fill_attr(entry,
fc_host_manufacturer(lport->host),
FC_FDMI_HBA_ATTR_MANUFACTURER_LEN);
@@ -244,7 +252,7 @@ static inline int fc_ct_ms_fill(struct fc_lport *lport,
put_unaligned_be16(FC_FDMI_HBA_ATTR_SERIALNUMBER,
&entry->type);
put_unaligned_be16(len, &entry->len);
- strncpy((char *)&entry->value,
+ fc_ct_ms_fill_attr(entry,
fc_host_serial_number(lport->host),
FC_FDMI_HBA_ATTR_SERIALNUMBER_LEN);
@@ -256,7 +264,7 @@ static inline int fc_ct_ms_fill(struct fc_lport *lport,
put_unaligned_be16(FC_FDMI_HBA_ATTR_MODEL,
&entry->type);
put_unaligned_be16(len, &entry->len);
- strncpy((char *)&entry->value,
+ fc_ct_ms_fill_attr(entry,
fc_host_model(lport->host),
FC_FDMI_HBA_ATTR_MODEL_LEN);
@@ -268,7 +276,7 @@ static inline int fc_ct_ms_fill(struct fc_lport *lport,
put_unaligned_be16(FC_FDMI_HBA_ATTR_MODELDESCRIPTION,
&entry->type);
put_unaligned_be16(len, &entry->len);
- strncpy((char *)&entry->value,
+ fc_ct_ms_fill_attr(entry,
fc_host_model_description(lport->host),
FC_FDMI_HBA_ATTR_MODELDESCR_LEN);
@@ -280,7 +288,7 @@ static inline int fc_ct_ms_fill(struct fc_lport *lport,
put_unaligned_be16(FC_FDMI_HBA_ATTR_HARDWAREVERSION,
&entry->type);
put_unaligned_be16(len, &entry->len);
- strncpy((char *)&entry->value,
+ fc_ct_ms_fill_attr(entry,
fc_host_hardware_version(lport->host),
FC_FDMI_HBA_ATTR_HARDWAREVERSION_LEN);
@@ -292,7 +300,7 @@ static inline int fc_ct_ms_fill(struct fc_lport *lport,
put_unaligned_be16(FC_FDMI_HBA_ATTR_DRIVERVERSION,
&entry->type);
put_unaligned_be16(len, &entry->len);
- strncpy((char *)&entry->value,
+ fc_ct_ms_fill_attr(entry,
fc_host_driver_version(lport->host),
FC_FDMI_HBA_ATTR_DRIVERVERSION_LEN);
@@ -304,7 +312,7 @@ static inline int fc_ct_ms_fill(struct fc_lport *lport,
put_unaligned_be16(FC_FDMI_HBA_ATTR_OPTIONROMVERSION,
&entry->type);
put_unaligned_be16(len, &entry->len);
- strncpy((char *)&entry->value,
+ fc_ct_ms_fill_attr(entry,
fc_host_optionrom_version(lport->host),
FC_FDMI_HBA_ATTR_OPTIONROMVERSION_LEN);
@@ -316,7 +324,7 @@ static inline int fc_ct_ms_fill(struct fc_lport *lport,
put_unaligned_be16(FC_FDMI_HBA_ATTR_FIRMWAREVERSION,
&entry->type);
put_unaligned_be16(len, &entry->len);
- strncpy((char *)&entry->value,
+ fc_ct_ms_fill_attr(entry,
fc_host_firmware_version(lport->host),
FC_FDMI_HBA_ATTR_FIRMWAREVERSION_LEN);
@@ -411,7 +419,7 @@ static inline int fc_ct_ms_fill(struct fc_lport *lport,
&entry->type);
put_unaligned_be16(len, &entry->len);
/* Use the sysfs device name */
- strncpy((char *)&entry->value,
+ fc_ct_ms_fill_attr(entry,
dev_name(&lport->host->shost_gendev),
strnlen(dev_name(&lport->host->shost_gendev),
FC_FDMI_PORT_ATTR_HOSTNAME_LEN));
@@ -425,12 +433,12 @@ static inline int fc_ct_ms_fill(struct fc_lport *lport,
&entry->type);
put_unaligned_be16(len, &entry->len);
if (strlen(fc_host_system_hostname(lport->host)))
- strncpy((char *)&entry->value,
+ fc_ct_ms_fill_attr(entry,
fc_host_system_hostname(lport->host),
strnlen(fc_host_system_hostname(lport->host),
FC_FDMI_PORT_ATTR_HOSTNAME_LEN));
else
- strncpy((char *)&entry->value,
+ fc_ct_ms_fill_attr(entry,
init_utsname()->nodename,
FC_FDMI_PORT_ATTR_HOSTNAME_LEN);
break;