From: Bart Van Assche <bvanassche@acm.org>
To: John Garry <john.garry@huawei.com>,
"Martin K . Petersen" <martin.petersen@oracle.com>
Cc: linux-scsi@vger.kernel.org, Christoph Hellwig <hch@lst.de>,
Ming Lei <ming.lei@redhat.com>, Hannes Reinecke <hare@suse.de>,
Mike Christie <michael.christie@oracle.com>,
Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>,
"James E.J. Bottomley" <jejb@linux.ibm.com>
Subject: Re: [PATCH v5 4/7] scsi: core: Introduce a new list for SCSI proc directory entries
Date: Thu, 29 Sep 2022 10:51:28 -0700 [thread overview]
Message-ID: <970dc24c-9c72-71be-0609-cfd4bfd43d5a@acm.org> (raw)
In-Reply-To: <1c7dade7-c821-e851-4b94-1c27ccd1fac6@huawei.com>
On 9/15/22 03:34, John Garry wrote:
> On 14/09/2022 23:56, Bart Van Assche wrote:
>> -int scsi_proc_hostdir_add(struct scsi_host_template *sht)
>> +int scsi_proc_hostdir_add(const struct scsi_host_template *sht)
>> {
>> - int ret = 0;
>> + struct scsi_proc_entry *e;
>> + int ret = -ENOMEM;
>> if (!sht->show_info)
>> 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) {
>> - printk(KERN_ERR "%s: proc_mkdir failed for %s\n",
>> - __func__, sht->proc_name);
>> - ret = -ENOMEM;
>> - }
>> + e = __scsi_lookup_proc_entry(sht);
>> + if (!e) {
>> + e = kzalloc(sizeof(*e), GFP_KERNEL);
>> + if (!e)
>> + goto unlock;
>
> maybe it's better to set ret = -ENOMEM here (and not initialize ret), as every other path it is set, AFAICS
I will make this change and also set ret if proc_mkdir() fails.
>> void scsi_proc_host_add(struct Scsi_Host *shost)
>> {
>> - struct scsi_host_template *sht = shost->hostt;
>> + const struct scsi_host_template *sht = shost->hostt;
>> + struct scsi_proc_entry *e;
>> struct proc_dir_entry *p;
>> char name[10];
>> - if (!sht->proc_dir)
>> + if (!sht->show_info)
>> + return;
>> +
>> + e = scsi_lookup_proc_entry(sht);
>
> hmm... this really should not fail, right?. Maybe an error message would be appropiate here (for failure).
If scsi_proc_hostdir_add() failed scsi_lookup_proc_entry() will return NULL.
I will add an error message.
>> + if (!e)
>> return;
>> sprintf(name,"%d", shost->host_no);
>> - p = proc_create_data(name, S_IRUGO | S_IWUSR,
>> - sht->proc_dir, &proc_scsi_ops, shost);
>> + p = proc_create_data(name, S_IRUGO | S_IWUSR, e->proc_dir,
>> + &proc_scsi_ops, shost);
>> if (!p)
>> printk(KERN_ERR "%s: Failed to register host %d in"
>> "%s\n", __func__, shost->host_no,
>> @@ -175,13 +241,19 @@ void scsi_proc_host_add(struct Scsi_Host *shost)
>> */
>> void scsi_proc_host_rm(struct Scsi_Host *shost)
>> {
>> + const struct scsi_host_template *sht = shost->hostt;
>> + struct scsi_proc_entry *e;
>> char name[10];
>> - if (!shost->hostt->proc_dir)
>> + if (!sht->show_info)
>> + return;
>> +
>> + e = scsi_lookup_proc_entry(sht);
>
> Same comment as scsi_proc_host_add
If scsi_proc_hostdir_add() failed scsi_lookup_proc_entry() will return NULL.
Thanks,
Bart.
next prev parent reply other threads:[~2022-09-29 17:51 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-09-14 22:56 [PATCH v5 0/7] Prepare for constifying SCSI host templates Bart Van Assche
2022-09-14 22:56 ` [PATCH v5 1/7] scsi: esas2r: Initialize two host template members implicitly Bart Van Assche
2022-09-14 22:56 ` [PATCH v5 2/7] scsi: esas2r: Introduce scsi_template_proc_dir() Bart Van Assche
2022-09-14 22:56 ` [PATCH v5 3/7] scsi: core: Fail host creation if creating the proc directory fails Bart Van Assche
2022-09-15 10:24 ` John Garry
2022-09-14 22:56 ` [PATCH v5 4/7] scsi: core: Introduce a new list for SCSI proc directory entries Bart Van Assche
2022-09-15 10:34 ` John Garry
2022-09-29 17:51 ` Bart Van Assche [this message]
2022-09-14 22:56 ` [PATCH v5 5/7] scsi: core: Fix a use-after-free related to releasing device handlers Bart Van Assche
2022-09-14 22:56 ` [PATCH v5 6/7] module: Improve support for asynchronous module exit code Bart Van Assche
2022-09-20 17:13 ` Bart Van Assche
2022-09-28 0:02 ` Luis Chamberlain
2022-09-28 18:17 ` Bart Van Assche
2022-09-30 19:39 ` Luis Chamberlain
2022-10-03 23:56 ` Luis Chamberlain
2022-10-04 0:24 ` Bart Van Assche
2022-09-28 1:09 ` Ming Lei
2022-09-28 19:27 ` Bart Van Assche
2022-09-29 1:10 ` Ming Lei
2022-09-29 17:27 ` Bart Van Assche
2022-09-14 22:56 ` [PATCH v5 7/7] scsi: core: Improve SCSI device removal Bart Van Assche
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=970dc24c-9c72-71be-0609-cfd4bfd43d5a@acm.org \
--to=bvanassche@acm.org \
--cc=hare@suse.de \
--cc=hch@lst.de \
--cc=jejb@linux.ibm.com \
--cc=john.garry@huawei.com \
--cc=krzysztof.kozlowski@linaro.org \
--cc=linux-scsi@vger.kernel.org \
--cc=martin.petersen@oracle.com \
--cc=michael.christie@oracle.com \
--cc=ming.lei@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox