diff mbox

[04/12] xen: make use of xenbus_read_unsigned() in xen-tpmfront

Message ID 1477932510-28594-5-git-send-email-jgross@suse.com (mailing list archive)
State New, archived
Headers show

Commit Message

Juergen Gross Oct. 31, 2016, 4:48 p.m. UTC
Use xenbus_read_unsigned() instead of xenbus_scanf() when possible.
This requires to change the type of one read from int to unsigned,
but this case has been wrong before: negative values are not allowed
for the modified case.

Cc: peterhuewe@gmx.de
Cc: tpmdd@selhorst.net
Cc: jarkko.sakkinen@linux.intel.com
Cc: jgunthorpe@obsidianresearch.com
Cc: tpmdd-devel@lists.sourceforge.net

Signed-off-by: Juergen Gross <jgross@suse.com>
---
 drivers/char/tpm/xen-tpmfront.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)

Comments

Jarkko Sakkinen Nov. 2, 2016, 10:34 a.m. UTC | #1
On Mon, Oct 31, 2016 at 05:48:22PM +0100, Juergen Gross wrote:
> Use xenbus_read_unsigned() instead of xenbus_scanf() when possible.
> This requires to change the type of one read from int to unsigned,
> but this case has been wrong before: negative values are not allowed
> for the modified case.
> 
> Cc: peterhuewe@gmx.de
> Cc: tpmdd@selhorst.net
> Cc: jarkko.sakkinen@linux.intel.com
> Cc: jgunthorpe@obsidianresearch.com
> Cc: tpmdd-devel@lists.sourceforge.net
> 
> Signed-off-by: Juergen Gross <jgross@suse.com>

Reviewed-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>

/Jarkko

> ---
>  drivers/char/tpm/xen-tpmfront.c | 8 ++------
>  1 file changed, 2 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/char/tpm/xen-tpmfront.c b/drivers/char/tpm/xen-tpmfront.c
> index 62028f4..50072cc 100644
> --- a/drivers/char/tpm/xen-tpmfront.c
> +++ b/drivers/char/tpm/xen-tpmfront.c
> @@ -337,18 +337,14 @@ static int tpmfront_resume(struct xenbus_device *dev)
>  static void backend_changed(struct xenbus_device *dev,
>  		enum xenbus_state backend_state)
>  {
> -	int val;
> -
>  	switch (backend_state) {
>  	case XenbusStateInitialised:
>  	case XenbusStateConnected:
>  		if (dev->state == XenbusStateConnected)
>  			break;
>  
> -		if (xenbus_scanf(XBT_NIL, dev->otherend,
> -				"feature-protocol-v2", "%d", &val) < 0)
> -			val = 0;
> -		if (!val) {
> +		if (!xenbus_read_unsigned(dev->otherend, "feature-protocol-v2",
> +					  0)) {
>  			xenbus_dev_fatal(dev, -EINVAL,
>  					"vTPM protocol 2 required");
>  			return;
> -- 
> 2.6.6
>
Jarkko Sakkinen Nov. 4, 2016, 4:26 a.m. UTC | #2
On Mon, Oct 31, 2016 at 05:48:22PM +0100, Juergen Gross wrote:
> Use xenbus_read_unsigned() instead of xenbus_scanf() when possible.
> This requires to change the type of one read from int to unsigned,
> but this case has been wrong before: negative values are not allowed
> for the modified case.
> 
> Cc: peterhuewe@gmx.de
> Cc: tpmdd@selhorst.net
> Cc: jarkko.sakkinen@linux.intel.com
> Cc: jgunthorpe@obsidianresearch.com
> Cc: tpmdd-devel@lists.sourceforge.net
> 
> Signed-off-by: Juergen Gross <jgross@suse.com>

Reviewed-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>

/Jarkko

> ---
>  drivers/char/tpm/xen-tpmfront.c | 8 ++------
>  1 file changed, 2 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/char/tpm/xen-tpmfront.c b/drivers/char/tpm/xen-tpmfront.c
> index 62028f4..50072cc 100644
> --- a/drivers/char/tpm/xen-tpmfront.c
> +++ b/drivers/char/tpm/xen-tpmfront.c
> @@ -337,18 +337,14 @@ static int tpmfront_resume(struct xenbus_device *dev)
>  static void backend_changed(struct xenbus_device *dev,
>  		enum xenbus_state backend_state)
>  {
> -	int val;
> -
>  	switch (backend_state) {
>  	case XenbusStateInitialised:
>  	case XenbusStateConnected:
>  		if (dev->state == XenbusStateConnected)
>  			break;
>  
> -		if (xenbus_scanf(XBT_NIL, dev->otherend,
> -				"feature-protocol-v2", "%d", &val) < 0)
> -			val = 0;
> -		if (!val) {
> +		if (!xenbus_read_unsigned(dev->otherend, "feature-protocol-v2",
> +					  0)) {
>  			xenbus_dev_fatal(dev, -EINVAL,
>  					"vTPM protocol 2 required");
>  			return;
> -- 
> 2.6.6
>
diff mbox

Patch

diff --git a/drivers/char/tpm/xen-tpmfront.c b/drivers/char/tpm/xen-tpmfront.c
index 62028f4..50072cc 100644
--- a/drivers/char/tpm/xen-tpmfront.c
+++ b/drivers/char/tpm/xen-tpmfront.c
@@ -337,18 +337,14 @@  static int tpmfront_resume(struct xenbus_device *dev)
 static void backend_changed(struct xenbus_device *dev,
 		enum xenbus_state backend_state)
 {
-	int val;
-
 	switch (backend_state) {
 	case XenbusStateInitialised:
 	case XenbusStateConnected:
 		if (dev->state == XenbusStateConnected)
 			break;
 
-		if (xenbus_scanf(XBT_NIL, dev->otherend,
-				"feature-protocol-v2", "%d", &val) < 0)
-			val = 0;
-		if (!val) {
+		if (!xenbus_read_unsigned(dev->otherend, "feature-protocol-v2",
+					  0)) {
 			xenbus_dev_fatal(dev, -EINVAL,
 					"vTPM protocol 2 required");
 			return;