powertop.lists.linux.dev archive mirror
 help / color / mirror / Atom feed
* [Powertop] [PATCH 1/4 v1] lib: refactor pci_access checks
@ 2017-09-08 22:36 Joe Konno
  0 siblings, 0 replies; 2+ messages in thread
From: Joe Konno @ 2017-09-08 22:36 UTC (permalink / raw)
  To: powertop

[-- Attachment #1: Type: text/plain, Size: 1016 bytes --]

From: Joe Konno <joe.konno(a)intel.com>

Pull the libpci initialization bits out and into its own dedicated function.

Signed-off-by: Joe Konno <joe.konno(a)intel.com>
---
 src/lib.cpp | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/src/lib.cpp b/src/lib.cpp
index 5e48f375d087..2b95e64f427b 100644
--- a/src/lib.cpp
+++ b/src/lib.cpp
@@ -296,16 +296,21 @@ void format_watts(double W, char *buffer, unsigned int len)
 #ifndef HAVE_NO_PCI
 static struct pci_access *pci_access;
 
+static void check_pci_access(void)
+{
+	if (!pci_access) {
+		pci_access = pci_alloc();
+		pci_init(pci_access);
+	}
+}
+
 char *pci_id_to_name(uint16_t vendor, uint16_t device, char *buffer, int len)
 {
 	char *ret;
 
 	buffer[0] = 0;
 
-	if (!pci_access) {
-		pci_access = pci_alloc();
-		pci_init(pci_access);
-	}
+	check_pci_access();
 
 	ret = pci_lookup_name(pci_access, buffer, len, PCI_LOOKUP_VENDOR | PCI_LOOKUP_DEVICE, vendor, device);
 
-- 
2.13.5


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [Powertop] [PATCH 1/4 v1] lib: refactor pci_access checks
@ 2017-09-09  7:18 Magnus Fromreide
  0 siblings, 0 replies; 2+ messages in thread
From: Magnus Fromreide @ 2017-09-09  7:18 UTC (permalink / raw)
  To: powertop

[-- Attachment #1: Type: text/plain, Size: 1593 bytes --]

On Fri, Sep 08, 2017 at 03:36:48PM -0700, Joe Konno wrote:
> From: Joe Konno <joe.konno(a)intel.com>
> 
> Pull the libpci initialization bits out and into its own dedicated function.

I think the name you choose for the function is odd since what it does is
that it creates the pci_access object if it doesn't exist. It certainly ain't
checking anything.

Maybe something along the lines of create_pci_access or initialize_pci_access
would be a better name?

> Signed-off-by: Joe Konno <joe.konno(a)intel.com>
> ---
>  src/lib.cpp | 13 +++++++++----
>  1 file changed, 9 insertions(+), 4 deletions(-)
> 
> diff --git a/src/lib.cpp b/src/lib.cpp
> index 5e48f375d087..2b95e64f427b 100644
> --- a/src/lib.cpp
> +++ b/src/lib.cpp
> @@ -296,16 +296,21 @@ void format_watts(double W, char *buffer, unsigned int len)
>  #ifndef HAVE_NO_PCI
>  static struct pci_access *pci_access;
>  
> +static void check_pci_access(void)
> +{
> +	if (!pci_access) {
> +		pci_access = pci_alloc();
> +		pci_init(pci_access);
> +	}
> +}
> +
>  char *pci_id_to_name(uint16_t vendor, uint16_t device, char *buffer, int len)
>  {
>  	char *ret;
>  
>  	buffer[0] = 0;
>  
> -	if (!pci_access) {
> -		pci_access = pci_alloc();
> -		pci_init(pci_access);
> -	}
> +	check_pci_access();
>  
>  	ret = pci_lookup_name(pci_access, buffer, len, PCI_LOOKUP_VENDOR | PCI_LOOKUP_DEVICE, vendor, device);
>  
> -- 
> 2.13.5
> 
> _______________________________________________
> PowerTop mailing list
> PowerTop(a)lists.01.org
> https://lists.01.org/mailman/listinfo/powertop

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2017-09-09  7:18 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-09-08 22:36 [Powertop] [PATCH 1/4 v1] lib: refactor pci_access checks Joe Konno
2017-09-09  7:18 Magnus Fromreide

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).