From: Michael Tokarev <mjt@tls.msk.ru>
To: zhanghailiang <zhang.zhanghailiang@huawei.com>, qemu-trivial@nongnu.org
Cc: qemu-devel@nongnu.org, mst@redhat.com
Subject: Re: [Qemu-trivial] [PATCH] piix: fix resource leak reported by Coverity
Date: Thu, 29 Oct 2015 10:40:23 +0300 [thread overview]
Message-ID: <5631CD67.9000109@msgid.tls.msk.ru> (raw)
In-Reply-To: <1442227210-24604-1-git-send-email-zhang.zhanghailiang@huawei.com>
[-- Attachment #1: Type: text/plain, Size: 1418 bytes --]
14.09.2015 13:40, zhanghailiang wrote:
> config_fd should be closed before return, or there will
> be a resource leak error.
>
> Signed-off-by: zhanghailiang <zhang.zhanghailiang@huawei.com>
> ---
> hw/pci-host/piix.c | 11 +++++++----
> 1 file changed, 7 insertions(+), 4 deletions(-)
>
> diff --git a/hw/pci-host/piix.c b/hw/pci-host/piix.c
> index 1fb71c8..7b2fbf9 100644
> --- a/hw/pci-host/piix.c
> +++ b/hw/pci-host/piix.c
> @@ -764,6 +764,7 @@ static int host_pci_config_read(int pos, int len, uint32_t val)
> /* Access real host bridge. */
> int rc = snprintf(path, size, "/sys/bus/pci/devices/%04x:%02x:%02x.%d/%s",
> 0, 0, 0, 0, "config");
> + int ret = 0;
>
> if (rc >= size || rc < 0) {
> return -ENODEV;
> @@ -775,16 +776,18 @@ static int host_pci_config_read(int pos, int len, uint32_t val)
> }
>
> if (lseek(config_fd, pos, SEEK_SET) != pos) {
> - return -errno;
> + ret = -errno;
> + goto out;
> }
> do {
> rc = read(config_fd, (uint8_t *)&val, len);
> } while (rc < 0 && (errno == EINTR || errno == EAGAIN));
> if (rc != len) {
> - return -errno;
> + ret = -errno;
> }
> -
> - return 0;
> +out:
> + close(config_fd);
> + return ret;
> }
>
> static int igd_pt_i440fx_initfn(struct PCIDevice *pci_dev)
How about the attached (untested)?
Thanks,
/mjt
[-- Attachment #2: piix-fix-resource-leak.diff --]
[-- Type: text/x-patch, Size: 1114 bytes --]
diff --git a/hw/pci-host/piix.c b/hw/pci-host/piix.c
index 7b2fbf9..42f847d 100644
--- a/hw/pci-host/piix.c
+++ b/hw/pci-host/piix.c
@@ -764,7 +764,6 @@ static int host_pci_config_read(int pos, int len, uint32_t val)
/* Access real host bridge. */
int rc = snprintf(path, size, "/sys/bus/pci/devices/%04x:%02x:%02x.%d/%s",
0, 0, 0, 0, "config");
- int ret = 0;
if (rc >= size || rc < 0) {
return -ENODEV;
@@ -774,20 +773,15 @@ static int host_pci_config_read(int pos, int len, uint32_t val)
if (config_fd < 0) {
return -ENODEV;
}
-
- if (lseek(config_fd, pos, SEEK_SET) != pos) {
- ret = -errno;
- goto out;
- }
do {
- rc = read(config_fd, (uint8_t *)&val, len);
+ rc = pread(config_fd, (uint8_t *)&val, len, pos);
} while (rc < 0 && (errno == EINTR || errno == EAGAIN));
+ close(config_fd);
if (rc != len) {
- ret = -errno;
+ return -errno;
}
-out:
- close(config_fd);
- return ret;
+
+ return 0;
}
static int igd_pt_i440fx_initfn(struct PCIDevice *pci_dev)
WARNING: multiple messages have this Message-ID (diff)
From: Michael Tokarev <mjt@tls.msk.ru>
To: zhanghailiang <zhang.zhanghailiang@huawei.com>, qemu-trivial@nongnu.org
Cc: qemu-devel@nongnu.org, mst@redhat.com
Subject: Re: [Qemu-devel] [PATCH] piix: fix resource leak reported by Coverity
Date: Thu, 29 Oct 2015 10:40:23 +0300 [thread overview]
Message-ID: <5631CD67.9000109@msgid.tls.msk.ru> (raw)
In-Reply-To: <1442227210-24604-1-git-send-email-zhang.zhanghailiang@huawei.com>
[-- Attachment #1: Type: text/plain, Size: 1418 bytes --]
14.09.2015 13:40, zhanghailiang wrote:
> config_fd should be closed before return, or there will
> be a resource leak error.
>
> Signed-off-by: zhanghailiang <zhang.zhanghailiang@huawei.com>
> ---
> hw/pci-host/piix.c | 11 +++++++----
> 1 file changed, 7 insertions(+), 4 deletions(-)
>
> diff --git a/hw/pci-host/piix.c b/hw/pci-host/piix.c
> index 1fb71c8..7b2fbf9 100644
> --- a/hw/pci-host/piix.c
> +++ b/hw/pci-host/piix.c
> @@ -764,6 +764,7 @@ static int host_pci_config_read(int pos, int len, uint32_t val)
> /* Access real host bridge. */
> int rc = snprintf(path, size, "/sys/bus/pci/devices/%04x:%02x:%02x.%d/%s",
> 0, 0, 0, 0, "config");
> + int ret = 0;
>
> if (rc >= size || rc < 0) {
> return -ENODEV;
> @@ -775,16 +776,18 @@ static int host_pci_config_read(int pos, int len, uint32_t val)
> }
>
> if (lseek(config_fd, pos, SEEK_SET) != pos) {
> - return -errno;
> + ret = -errno;
> + goto out;
> }
> do {
> rc = read(config_fd, (uint8_t *)&val, len);
> } while (rc < 0 && (errno == EINTR || errno == EAGAIN));
> if (rc != len) {
> - return -errno;
> + ret = -errno;
> }
> -
> - return 0;
> +out:
> + close(config_fd);
> + return ret;
> }
>
> static int igd_pt_i440fx_initfn(struct PCIDevice *pci_dev)
How about the attached (untested)?
Thanks,
/mjt
[-- Attachment #2: piix-fix-resource-leak.diff --]
[-- Type: text/x-patch, Size: 1114 bytes --]
diff --git a/hw/pci-host/piix.c b/hw/pci-host/piix.c
index 7b2fbf9..42f847d 100644
--- a/hw/pci-host/piix.c
+++ b/hw/pci-host/piix.c
@@ -764,7 +764,6 @@ static int host_pci_config_read(int pos, int len, uint32_t val)
/* Access real host bridge. */
int rc = snprintf(path, size, "/sys/bus/pci/devices/%04x:%02x:%02x.%d/%s",
0, 0, 0, 0, "config");
- int ret = 0;
if (rc >= size || rc < 0) {
return -ENODEV;
@@ -774,20 +773,15 @@ static int host_pci_config_read(int pos, int len, uint32_t val)
if (config_fd < 0) {
return -ENODEV;
}
-
- if (lseek(config_fd, pos, SEEK_SET) != pos) {
- ret = -errno;
- goto out;
- }
do {
- rc = read(config_fd, (uint8_t *)&val, len);
+ rc = pread(config_fd, (uint8_t *)&val, len, pos);
} while (rc < 0 && (errno == EINTR || errno == EAGAIN));
+ close(config_fd);
if (rc != len) {
- ret = -errno;
+ return -errno;
}
-out:
- close(config_fd);
- return ret;
+
+ return 0;
}
static int igd_pt_i440fx_initfn(struct PCIDevice *pci_dev)
next prev parent reply other threads:[~2015-10-29 7:40 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-09-14 10:40 [Qemu-trivial] [PATCH] piix: fix resource leak reported by Coverity zhanghailiang
2015-09-14 10:40 ` [Qemu-devel] " zhanghailiang
2015-10-16 12:01 ` [Qemu-trivial] " Stefan Hajnoczi
2015-10-16 12:01 ` Stefan Hajnoczi
2015-10-29 7:40 ` Michael Tokarev [this message]
2015-10-29 7:40 ` Michael Tokarev
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=5631CD67.9000109@msgid.tls.msk.ru \
--to=mjt@tls.msk.ru \
--cc=mst@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=qemu-trivial@nongnu.org \
--cc=zhang.zhanghailiang@huawei.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.