Skip to content

Commit

Permalink
scsi: mpi3mr: Clean up mpi3mr_print_ioc_info()
Browse files Browse the repository at this point in the history
This function is more complicated than necessary.

If we change from scnprintf() to snprintf() that lets us remove the if
bytes_wrote < sizeof(protocol) checks.  Also, we can use bytes_wrote ? ","
: "" to print the comma and remove the separate if statement and the
"is_string_nonempty" variable.

[mkp: a few formatting cleanups and s/wrote/written/]

Link: https://lore.kernel.org/r/20210916132605.GF25094@kili
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
  • Loading branch information
Dan Carpenter authored and Martin K. Petersen committed Oct 5, 2021
1 parent 4084a72 commit 76a4f7c
Showing 1 changed file with 9 additions and 23 deletions.
32 changes: 9 additions & 23 deletions drivers/scsi/mpi3mr/mpi3mr_fw.c
Original file line number Diff line number Diff line change
Expand Up @@ -3018,11 +3018,10 @@ static const struct {
static void
mpi3mr_print_ioc_info(struct mpi3mr_ioc *mrioc)
{
int i = 0, bytes_wrote = 0;
int i = 0, bytes_written = 0;
char personality[16];
char protocol[50] = {0};
char capabilities[100] = {0};
bool is_string_nonempty = false;
struct mpi3mr_compimg_ver *fwver = &mrioc->facts.fw_ver;

switch (mrioc->facts.personality) {
Expand All @@ -3046,39 +3045,26 @@ mpi3mr_print_ioc_info(struct mpi3mr_ioc *mrioc)
for (i = 0; i < ARRAY_SIZE(mpi3mr_protocols); i++) {
if (mrioc->facts.protocol_flags &
mpi3mr_protocols[i].protocol) {
if (is_string_nonempty &&
(bytes_wrote < sizeof(protocol)))
bytes_wrote += snprintf(protocol + bytes_wrote,
(sizeof(protocol) - bytes_wrote), ",");

if (bytes_wrote < sizeof(protocol))
bytes_wrote += snprintf(protocol + bytes_wrote,
(sizeof(protocol) - bytes_wrote), "%s",
bytes_written += snprintf(protocol + bytes_written,
sizeof(protocol) - bytes_written, "%s%s",
bytes_written ? "," : "",
mpi3mr_protocols[i].name);
is_string_nonempty = true;
}
}

bytes_wrote = 0;
is_string_nonempty = false;
bytes_written = 0;
for (i = 0; i < ARRAY_SIZE(mpi3mr_capabilities); i++) {
if (mrioc->facts.protocol_flags &
mpi3mr_capabilities[i].capability) {
if (is_string_nonempty &&
(bytes_wrote < sizeof(capabilities)))
bytes_wrote += snprintf(capabilities + bytes_wrote,
(sizeof(capabilities) - bytes_wrote), ",");

if (bytes_wrote < sizeof(capabilities))
bytes_wrote += snprintf(capabilities + bytes_wrote,
(sizeof(capabilities) - bytes_wrote), "%s",
bytes_written += snprintf(capabilities + bytes_written,
sizeof(capabilities) - bytes_written, "%s%s",
bytes_written ? "," : "",
mpi3mr_capabilities[i].name);
is_string_nonempty = true;
}
}

ioc_info(mrioc, "Protocol=(%s), Capabilities=(%s)\n",
protocol, capabilities);
protocol, capabilities);
}

/**
Expand Down

0 comments on commit 76a4f7c

Please sign in to comment.