Skip to content

Commit

Permalink
scsi: core: Fail host creation if creating the proc directory fails
Browse files Browse the repository at this point in the history
Users expect that the contents of /proc/scsi is in sync with the contents
of /sys/class/scsi_host. Hence fail host creation if creating the proc
directory fails.

Suggested-by: John Garry <[email protected]>
Reviewed-by: John Garry <[email protected]>
Cc: Christoph Hellwig <[email protected]>
Cc: Ming Lei <[email protected]>
Cc: Hannes Reinecke <[email protected]>
Cc: Mike Christie <[email protected]>
Cc: Krzysztof Kozlowski <[email protected]>
Signed-off-by: Bart Van Assche <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Martin K. Petersen <[email protected]>
  • Loading branch information
bvanassche authored and martinkpetersen committed Oct 18, 2022
1 parent 77916da commit ecca3f9
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
3 changes: 2 additions & 1 deletion drivers/scsi/hosts.c
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,8 @@ struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *sht, int privsize)
"failed to create tmf workq\n");
goto fail;
}
scsi_proc_hostdir_add(shost->hostt);
if (scsi_proc_hostdir_add(shost->hostt) < 0)
goto fail;
return shost;
fail:
/*
Expand Down
4 changes: 2 additions & 2 deletions drivers/scsi/scsi_priv.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,14 +111,14 @@ extern void scsi_evt_thread(struct work_struct *work);

/* scsi_proc.c */
#ifdef CONFIG_SCSI_PROC_FS
extern void scsi_proc_hostdir_add(struct scsi_host_template *);
extern int scsi_proc_hostdir_add(struct scsi_host_template *);
extern void scsi_proc_hostdir_rm(struct scsi_host_template *);
extern void scsi_proc_host_add(struct Scsi_Host *);
extern void scsi_proc_host_rm(struct Scsi_Host *);
extern int scsi_init_procfs(void);
extern void scsi_exit_procfs(void);
#else
# define scsi_proc_hostdir_add(sht) do { } while (0)
# define scsi_proc_hostdir_add(sht) 0
# define scsi_proc_hostdir_rm(sht) do { } while (0)
# define scsi_proc_host_add(shost) do { } while (0)
# define scsi_proc_host_rm(shost) do { } while (0)
Expand Down
13 changes: 9 additions & 4 deletions drivers/scsi/scsi_proc.c
Original file line number Diff line number Diff line change
Expand Up @@ -108,20 +108,25 @@ static const struct proc_ops proc_scsi_ops = {
*
* Sets sht->proc_dir to the new directory.
*/

void scsi_proc_hostdir_add(struct scsi_host_template *sht)
int scsi_proc_hostdir_add(struct scsi_host_template *sht)
{
int ret = 0;

if (!sht->show_info)
return;
return 0;

mutex_lock(&global_host_template_mutex);
if (!sht->present++) {
sht->proc_dir = proc_mkdir(sht->proc_name, proc_scsi);
if (!sht->proc_dir)
if (!sht->proc_dir) {
printk(KERN_ERR "%s: proc_mkdir failed for %s\n",
__func__, sht->proc_name);
ret = -ENOMEM;
}
}
mutex_unlock(&global_host_template_mutex);

return ret;
}

/**
Expand Down

0 comments on commit ecca3f9

Please sign in to comment.