Skip to content

Commit 5d7ef44

Browse files
Justin Teemartinkpetersen
authored andcommitted
scsi: lpfc: Use switch case statements in DIF debugfs handlers
With the introduction of aux numbers for debugfs entries, there's no need to use the if-else-if clause based on debugfs entry pointers. Update both the lpfc_debugfs_dif_err_read and lpfc_debugfs_dif_err_write routines to use switch case based on aux instead. Reported-by: Al Viro <viro@zeniv.linux.org.uk> Closes: https://lore.kernel.org/linux-fsdevel/20250702212917.GK3406663@ZenIV/ Signed-off-by: Justin Tee <justin.tee@broadcom.com> Message-ID: <20250915180811.137530-11-justintee8345@gmail.com> Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
1 parent 06d3c77 commit 5d7ef44

2 files changed

Lines changed: 83 additions & 58 deletions

File tree

drivers/scsi/lpfc/lpfc_debugfs.c

Lines changed: 82 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -2373,93 +2373,117 @@ lpfc_debugfs_dumpHostSlim_open(struct inode *inode, struct file *file)
23732373

23742374
static ssize_t
23752375
lpfc_debugfs_dif_err_read(struct file *file, char __user *buf,
2376-
size_t nbytes, loff_t *ppos)
2376+
size_t nbytes, loff_t *ppos)
23772377
{
23782378
struct lpfc_hba *phba = file->private_data;
23792379
int kind = debugfs_get_aux_num(file);
2380-
char cbuf[32];
2381-
uint64_t tmp = 0;
2380+
char cbuf[32] = {0};
23822381
int cnt = 0;
23832382

2384-
if (kind == writeGuard)
2385-
cnt = scnprintf(cbuf, 32, "%u\n", phba->lpfc_injerr_wgrd_cnt);
2386-
else if (kind == writeApp)
2387-
cnt = scnprintf(cbuf, 32, "%u\n", phba->lpfc_injerr_wapp_cnt);
2388-
else if (kind == writeRef)
2389-
cnt = scnprintf(cbuf, 32, "%u\n", phba->lpfc_injerr_wref_cnt);
2390-
else if (kind == readGuard)
2391-
cnt = scnprintf(cbuf, 32, "%u\n", phba->lpfc_injerr_rgrd_cnt);
2392-
else if (kind == readApp)
2393-
cnt = scnprintf(cbuf, 32, "%u\n", phba->lpfc_injerr_rapp_cnt);
2394-
else if (kind == readRef)
2395-
cnt = scnprintf(cbuf, 32, "%u\n", phba->lpfc_injerr_rref_cnt);
2396-
else if (kind == InjErrNPortID)
2397-
cnt = scnprintf(cbuf, 32, "0x%06x\n",
2383+
switch (kind) {
2384+
case writeGuard:
2385+
cnt = scnprintf(cbuf, sizeof(cbuf), "%u\n",
2386+
phba->lpfc_injerr_wgrd_cnt);
2387+
break;
2388+
case writeApp:
2389+
cnt = scnprintf(cbuf, sizeof(cbuf), "%u\n",
2390+
phba->lpfc_injerr_wapp_cnt);
2391+
break;
2392+
case writeRef:
2393+
cnt = scnprintf(cbuf, sizeof(cbuf), "%u\n",
2394+
phba->lpfc_injerr_wref_cnt);
2395+
break;
2396+
case readGuard:
2397+
cnt = scnprintf(cbuf, sizeof(cbuf), "%u\n",
2398+
phba->lpfc_injerr_rgrd_cnt);
2399+
break;
2400+
case readApp:
2401+
cnt = scnprintf(cbuf, sizeof(cbuf), "%u\n",
2402+
phba->lpfc_injerr_rapp_cnt);
2403+
break;
2404+
case readRef:
2405+
cnt = scnprintf(cbuf, sizeof(cbuf), "%u\n",
2406+
phba->lpfc_injerr_rref_cnt);
2407+
break;
2408+
case InjErrNPortID:
2409+
cnt = scnprintf(cbuf, sizeof(cbuf), "0x%06x\n",
23982410
phba->lpfc_injerr_nportid);
2399-
else if (kind == InjErrWWPN) {
2400-
memcpy(&tmp, &phba->lpfc_injerr_wwpn, sizeof(struct lpfc_name));
2401-
tmp = cpu_to_be64(tmp);
2402-
cnt = scnprintf(cbuf, 32, "0x%016llx\n", tmp);
2403-
} else if (kind == InjErrLBA) {
2404-
if (phba->lpfc_injerr_lba == (sector_t)(-1))
2405-
cnt = scnprintf(cbuf, 32, "off\n");
2411+
break;
2412+
case InjErrWWPN:
2413+
cnt = scnprintf(cbuf, sizeof(cbuf), "0x%016llx\n",
2414+
be64_to_cpu(phba->lpfc_injerr_wwpn.u.wwn_be));
2415+
break;
2416+
case InjErrLBA:
2417+
if (phba->lpfc_injerr_lba == LPFC_INJERR_LBA_OFF)
2418+
cnt = scnprintf(cbuf, sizeof(cbuf), "off\n");
24062419
else
2407-
cnt = scnprintf(cbuf, 32, "0x%llx\n",
2408-
(uint64_t) phba->lpfc_injerr_lba);
2409-
} else
2410-
lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2411-
"0547 Unknown debugfs error injection entry\n");
2420+
cnt = scnprintf(cbuf, sizeof(cbuf), "0x%llx\n",
2421+
(uint64_t)phba->lpfc_injerr_lba);
2422+
break;
2423+
default:
2424+
lpfc_log_msg(phba, KERN_WARNING, LOG_INIT,
2425+
"0547 Unknown debugfs error injection entry\n");
2426+
break;
2427+
}
24122428

24132429
return simple_read_from_buffer(buf, nbytes, ppos, &cbuf, cnt);
24142430
}
24152431

24162432
static ssize_t
24172433
lpfc_debugfs_dif_err_write(struct file *file, const char __user *buf,
2418-
size_t nbytes, loff_t *ppos)
2434+
size_t nbytes, loff_t *ppos)
24192435
{
24202436
struct lpfc_hba *phba = file->private_data;
24212437
int kind = debugfs_get_aux_num(file);
2422-
char dstbuf[33];
2423-
uint64_t tmp = 0;
2424-
int size;
2438+
char dstbuf[33] = {0};
2439+
unsigned long long tmp;
2440+
unsigned long size;
24252441

2426-
memset(dstbuf, 0, 33);
2427-
size = (nbytes < 32) ? nbytes : 32;
2442+
size = (nbytes < (sizeof(dstbuf) - 1)) ? nbytes : (sizeof(dstbuf) - 1);
24282443
if (copy_from_user(dstbuf, buf, size))
24292444
return -EFAULT;
24302445

2431-
if (kind == InjErrLBA) {
2432-
if ((dstbuf[0] == 'o') && (dstbuf[1] == 'f') &&
2433-
(dstbuf[2] == 'f'))
2434-
tmp = (uint64_t)(-1);
2446+
if (kstrtoull(dstbuf, 0, &tmp)) {
2447+
if (kind != InjErrLBA || !strstr(dstbuf, "off"))
2448+
return -EINVAL;
24352449
}
24362450

2437-
if ((tmp == 0) && (kstrtoull(dstbuf, 0, &tmp)))
2438-
return -EINVAL;
2439-
2440-
if (kind == writeGuard)
2451+
switch (kind) {
2452+
case writeGuard:
24412453
phba->lpfc_injerr_wgrd_cnt = (uint32_t)tmp;
2442-
else if (kind == writeApp)
2454+
break;
2455+
case writeApp:
24432456
phba->lpfc_injerr_wapp_cnt = (uint32_t)tmp;
2444-
else if (kind == writeRef)
2457+
break;
2458+
case writeRef:
24452459
phba->lpfc_injerr_wref_cnt = (uint32_t)tmp;
2446-
else if (kind == readGuard)
2460+
break;
2461+
case readGuard:
24472462
phba->lpfc_injerr_rgrd_cnt = (uint32_t)tmp;
2448-
else if (kind == readApp)
2463+
break;
2464+
case readApp:
24492465
phba->lpfc_injerr_rapp_cnt = (uint32_t)tmp;
2450-
else if (kind == readRef)
2466+
break;
2467+
case readRef:
24512468
phba->lpfc_injerr_rref_cnt = (uint32_t)tmp;
2452-
else if (kind == InjErrLBA)
2453-
phba->lpfc_injerr_lba = (sector_t)tmp;
2454-
else if (kind == InjErrNPortID)
2469+
break;
2470+
case InjErrLBA:
2471+
if (strstr(dstbuf, "off"))
2472+
phba->lpfc_injerr_lba = LPFC_INJERR_LBA_OFF;
2473+
else
2474+
phba->lpfc_injerr_lba = (sector_t)tmp;
2475+
break;
2476+
case InjErrNPortID:
24552477
phba->lpfc_injerr_nportid = (uint32_t)(tmp & Mask_DID);
2456-
else if (kind == InjErrWWPN) {
2457-
tmp = cpu_to_be64(tmp);
2458-
memcpy(&phba->lpfc_injerr_wwpn, &tmp, sizeof(struct lpfc_name));
2459-
} else
2460-
lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2461-
"0548 Unknown debugfs error injection entry\n");
2462-
2478+
break;
2479+
case InjErrWWPN:
2480+
phba->lpfc_injerr_wwpn.u.wwn_be = cpu_to_be64(tmp);
2481+
break;
2482+
default:
2483+
lpfc_log_msg(phba, KERN_WARNING, LOG_INIT,
2484+
"0548 Unknown debugfs error injection entry\n");
2485+
break;
2486+
}
24632487
return nbytes;
24642488
}
24652489

drivers/scsi/lpfc/lpfc_hw.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,7 @@ struct lpfc_name {
366366
} s;
367367
uint8_t wwn[8];
368368
uint64_t name __packed __aligned(4);
369+
__be64 wwn_be __packed __aligned(4);
369370
} u;
370371
};
371372

0 commit comments

Comments
 (0)