Message ID | 20210902174105.2418771-8-mcgrof@kernel.org (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | block: 5th batch of add_disk() error handling conversions | expand |
On Thu, Sep 02, 2021 at 10:41:03AM -0700, Luis Chamberlain wrote: > We never checked for errors on add_disk() as this function > returned void. Now that this is fixed, use the shiny new > error handling. > > Signed-off-by: Luis Chamberlain <mcgrof@kernel.org> > --- > drivers/s390/block/dcssblk.c | 4 +++- > 1 file changed, 3 insertions(+), 1 deletion(-) > > diff --git a/drivers/s390/block/dcssblk.c b/drivers/s390/block/dcssblk.c > index 5be3d1c39a78..b0fd5009a12e 100644 > --- a/drivers/s390/block/dcssblk.c > +++ b/drivers/s390/block/dcssblk.c > @@ -696,7 +696,9 @@ dcssblk_add_store(struct device *dev, struct device_attribute *attr, const char > } > > get_device(&dev_info->dev); > - device_add_disk(&dev_info->dev, dev_info->gd, NULL); > + rc = device_add_disk(&dev_info->dev, dev_info->gd, NULL); > + if (rc) > + goto put_dev; This looks not correct to me. We seem to have now in case of an error: - reference count imbalance (= memory leak) - dax cleanup is missing
On Fri, Sep 03, 2021 at 04:08:48PM +0200, Heiko Carstens wrote: > On Thu, Sep 02, 2021 at 10:41:03AM -0700, Luis Chamberlain wrote: > > We never checked for errors on add_disk() as this function > > returned void. Now that this is fixed, use the shiny new > > error handling. > > > > Signed-off-by: Luis Chamberlain <mcgrof@kernel.org> > > --- > > drivers/s390/block/dcssblk.c | 4 +++- > > 1 file changed, 3 insertions(+), 1 deletion(-) > > > > diff --git a/drivers/s390/block/dcssblk.c b/drivers/s390/block/dcssblk.c > > index 5be3d1c39a78..b0fd5009a12e 100644 > > --- a/drivers/s390/block/dcssblk.c > > +++ b/drivers/s390/block/dcssblk.c > > @@ -696,7 +696,9 @@ dcssblk_add_store(struct device *dev, struct device_attribute *attr, const char > > } > > > > get_device(&dev_info->dev); > > - device_add_disk(&dev_info->dev, dev_info->gd, NULL); > > + rc = device_add_disk(&dev_info->dev, dev_info->gd, NULL); > > + if (rc) > > + goto put_dev; > > This looks not correct to me. We seem to have now in case of an error: > > - reference count imbalance (= memory leak) > - dax cleanup is missing Care to provide an alternative? Luis
On Fri, 3 Sep 2021 18:46:26 -0700 Luis Chamberlain <mcgrof@kernel.org> wrote: > On Fri, Sep 03, 2021 at 04:08:48PM +0200, Heiko Carstens wrote: > > On Thu, Sep 02, 2021 at 10:41:03AM -0700, Luis Chamberlain wrote: > > > We never checked for errors on add_disk() as this function > > > returned void. Now that this is fixed, use the shiny new > > > error handling. > > > > > > Signed-off-by: Luis Chamberlain <mcgrof@kernel.org> > > > --- > > > drivers/s390/block/dcssblk.c | 4 +++- > > > 1 file changed, 3 insertions(+), 1 deletion(-) > > > > > > diff --git a/drivers/s390/block/dcssblk.c b/drivers/s390/block/dcssblk.c > > > index 5be3d1c39a78..b0fd5009a12e 100644 > > > --- a/drivers/s390/block/dcssblk.c > > > +++ b/drivers/s390/block/dcssblk.c > > > @@ -696,7 +696,9 @@ dcssblk_add_store(struct device *dev, struct device_attribute *attr, const char > > > } > > > > > > get_device(&dev_info->dev); > > > - device_add_disk(&dev_info->dev, dev_info->gd, NULL); > > > + rc = device_add_disk(&dev_info->dev, dev_info->gd, NULL); > > > + if (rc) > > > + goto put_dev; > > > > This looks not correct to me. We seem to have now in case of an error: > > > > - reference count imbalance (= memory leak) > > - dax cleanup is missing > > Care to provide an alternative? See patch below: From 7053b5f8c0a126c3ef450de3668d9963bd68ceaa Mon Sep 17 00:00:00 2001 From: Gerald Schaefer <gerald.schaefer@linux.ibm.com> Date: Mon, 6 Sep 2021 13:18:53 +0200 Subject: [PATCH] s390/block/dcssblk: add error handling support for add_disk() Signed-off-by: Gerald Schaefer <gerald.schaefer@linux.ibm.com> --- drivers/s390/block/dcssblk.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/drivers/s390/block/dcssblk.c b/drivers/s390/block/dcssblk.c index 5be3d1c39a78..0741a9321712 100644 --- a/drivers/s390/block/dcssblk.c +++ b/drivers/s390/block/dcssblk.c @@ -696,7 +696,9 @@ dcssblk_add_store(struct device *dev, struct device_attribute *attr, const char } get_device(&dev_info->dev); - device_add_disk(&dev_info->dev, dev_info->gd, NULL); + rc = device_add_disk(&dev_info->dev, dev_info->gd, NULL); + if (rc) + goto out_dax; switch (dev_info->segment_type) { case SEG_TYPE_SR: @@ -712,6 +714,10 @@ dcssblk_add_store(struct device *dev, struct device_attribute *attr, const char rc = count; goto out; +out_dax: + put_device(&dev_info->dev); + kill_dax(dev_info->dax_dev); + put_dax(dev_info->dax_dev); put_dev: list_del(&dev_info->lh); blk_cleanup_disk(dev_info->gd);
On Mon, Sep 06, 2021 at 01:43:46PM +0200, Gerald Schaefer wrote: > On Fri, 3 Sep 2021 18:46:26 -0700 > Luis Chamberlain <mcgrof@kernel.org> wrote: > > > > + rc = device_add_disk(&dev_info->dev, dev_info->gd, NULL); > > > > + if (rc) > > > > + goto put_dev; > > > > > > This looks not correct to me. We seem to have now in case of an error: > > > > > > - reference count imbalance (= memory leak) > > > - dax cleanup is missing > > > > Care to provide an alternative? > > See patch below: > > From 7053b5f8c0a126c3ef450de3668d9963bd68ceaa Mon Sep 17 00:00:00 2001 > From: Gerald Schaefer <gerald.schaefer@linux.ibm.com> > Date: Mon, 6 Sep 2021 13:18:53 +0200 > Subject: [PATCH] s390/block/dcssblk: add error handling support for add_disk() > > Signed-off-by: Gerald Schaefer <gerald.schaefer@linux.ibm.com> > --- > drivers/s390/block/dcssblk.c | 8 +++++++- > 1 file changed, 7 insertions(+), 1 deletion(-) Thanks Gerald! FWIW: Acked-by: Heiko Carstens <hca@linux.ibm.com>
On Mon, Sep 06, 2021 at 01:43:46PM +0200, Gerald Schaefer wrote: > On Fri, 3 Sep 2021 18:46:26 -0700 > Luis Chamberlain <mcgrof@kernel.org> wrote: > > > On Fri, Sep 03, 2021 at 04:08:48PM +0200, Heiko Carstens wrote: > > > On Thu, Sep 02, 2021 at 10:41:03AM -0700, Luis Chamberlain wrote: > > > > We never checked for errors on add_disk() as this function > > > > returned void. Now that this is fixed, use the shiny new > > > > error handling. > > > > > > > > Signed-off-by: Luis Chamberlain <mcgrof@kernel.org> > > > > --- > > > > drivers/s390/block/dcssblk.c | 4 +++- > > > > 1 file changed, 3 insertions(+), 1 deletion(-) > > > > > > > > diff --git a/drivers/s390/block/dcssblk.c b/drivers/s390/block/dcssblk.c > > > > index 5be3d1c39a78..b0fd5009a12e 100644 > > > > --- a/drivers/s390/block/dcssblk.c > > > > +++ b/drivers/s390/block/dcssblk.c > > > > @@ -696,7 +696,9 @@ dcssblk_add_store(struct device *dev, struct device_attribute *attr, const char > > > > } > > > > > > > > get_device(&dev_info->dev); > > > > - device_add_disk(&dev_info->dev, dev_info->gd, NULL); > > > > + rc = device_add_disk(&dev_info->dev, dev_info->gd, NULL); > > > > + if (rc) > > > > + goto put_dev; > > > > > > This looks not correct to me. We seem to have now in case of an error: > > > > > > - reference count imbalance (= memory leak) > > > - dax cleanup is missing > > > > Care to provide an alternative? > > See patch below: Thanks! Will you queue this up on your end or do would you prefer for me to roll this into my tree and eventually resend with the rest? Luis
On Mon, Sep 13, 2021 at 09:53:14AM -0700, Luis Chamberlain wrote: > On Mon, Sep 06, 2021 at 01:43:46PM +0200, Gerald Schaefer wrote: > > On Fri, 3 Sep 2021 18:46:26 -0700 > > Luis Chamberlain <mcgrof@kernel.org> wrote: > > > > > On Fri, Sep 03, 2021 at 04:08:48PM +0200, Heiko Carstens wrote: > > > > On Thu, Sep 02, 2021 at 10:41:03AM -0700, Luis Chamberlain wrote: > > > > > We never checked for errors on add_disk() as this function > > > > > returned void. Now that this is fixed, use the shiny new > > > > > error handling. > > > > > > > > > > Signed-off-by: Luis Chamberlain <mcgrof@kernel.org> > > > > > --- > > > > > drivers/s390/block/dcssblk.c | 4 +++- > > > > > 1 file changed, 3 insertions(+), 1 deletion(-) > > > > > > > > > > diff --git a/drivers/s390/block/dcssblk.c b/drivers/s390/block/dcssblk.c > > > > > index 5be3d1c39a78..b0fd5009a12e 100644 > > > > > --- a/drivers/s390/block/dcssblk.c > > > > > +++ b/drivers/s390/block/dcssblk.c > > > > > @@ -696,7 +696,9 @@ dcssblk_add_store(struct device *dev, struct device_attribute *attr, const char > > > > > } > > > > > > > > > > get_device(&dev_info->dev); > > > > > - device_add_disk(&dev_info->dev, dev_info->gd, NULL); > > > > > + rc = device_add_disk(&dev_info->dev, dev_info->gd, NULL); > > > > > + if (rc) > > > > > + goto put_dev; > > > > > > > > This looks not correct to me. We seem to have now in case of an error: > > > > > > > > - reference count imbalance (= memory leak) > > > > - dax cleanup is missing > > > > > > Care to provide an alternative? > > > > See patch below: > > Thanks! Will you queue this up on your end or do would you > prefer for me to roll this into my tree and eventually resend > with the rest? Please add the patch to your tree.
diff --git a/drivers/s390/block/dcssblk.c b/drivers/s390/block/dcssblk.c index 5be3d1c39a78..b0fd5009a12e 100644 --- a/drivers/s390/block/dcssblk.c +++ b/drivers/s390/block/dcssblk.c @@ -696,7 +696,9 @@ dcssblk_add_store(struct device *dev, struct device_attribute *attr, const char } get_device(&dev_info->dev); - device_add_disk(&dev_info->dev, dev_info->gd, NULL); + rc = device_add_disk(&dev_info->dev, dev_info->gd, NULL); + if (rc) + goto put_dev; switch (dev_info->segment_type) { case SEG_TYPE_SR:
We never checked for errors on add_disk() as this function returned void. Now that this is fixed, use the shiny new error handling. Signed-off-by: Luis Chamberlain <mcgrof@kernel.org> --- drivers/s390/block/dcssblk.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)