mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Kylene Jo Hall <kjhall@us.ibm.com>
To: Andrew Morton <akpm@osdl.org>
Cc: Marcel Selhorst <selhorst@crypto.rub.de>,
	linux-kernel@vger.kernel.org, castet.matthieu@free.fr
Subject: [PATCH] TPM: cleanups
Date: Fri, 11 Nov 2005 14:11:03 -0600	[thread overview]
Message-ID: <1131739863.5048.18.camel@localhost.localdomain> (raw)
In-Reply-To: <20051027145535.0741b647.akpm@osdl.org>

Patch to clean up a couple of issues recently pointed out with the
driver.  The fix for issue (c) was also pointed out by Steve Tate on the
tpm-devel list.


On Thu, 2005-10-27 at 14:55 -0700, Andrew Morton wrote: 
> Have just taken a wander through the TPM driver.  I couldn't help myself - are
> you OK with the below trivial changes?
> 
> Other things:
> 
> a)
> 
> ssize_t tpm_read(struct file * file, char __user *buf,
> 		 size_t size, loff_t * off)
> {
> f	struct tpm_chip *chip = file->private_data;
> 	int ret_size;
> 
> 	del_singleshot_timer_sync(&chip->user_read_timer);
> 	ret_size = atomic_read(&chip->data_pending);
> 	atomic_set(&chip->data_pending, 0);
> 	if (ret_size > 0) {	/* relay data */
> 		if (size < ret_size)
> 			ret_size = size;
> 
> 		down(&chip->buffer_mutex);
> 		if (copy_to_user
> 		    ((void __user *) buf, chip->data_buffer, ret_size))
> 			ret_size = -EFAULT;
> 
> Why is the first arg to copy_to_user() typecast in this manner?  I don't
> think the cast needs to be there?
> 
Fixed in the patch below.

> 
> b) user_reader_timeout does down() from within a timer handler!  That's
>    deadlocky and is illegal - timer handlers are run from interrupt
>    context.
> 
>    This should have generated a storm of runtime warnings if tested with
>    CONFIG_PREEMPT and CONFIG_DEBUG_SPINLOCK_SLEEP.  Developers really should
>    enable all the kernel debug options during development - they find bugs.
> 
>    Suggest you convert this to using schedule_work() or
>    schedule_delayed_work(). 
> 
I'll look into this.

> c) In tpm_remove_hardware():
> 
> 	dev_mask[chip->dev_num / TPM_NUM_MASK_ENTRIES ] &= !(1 << (chip->dev_num % TPM_NUM_MASK_ENTRIES));
> 
>    Is that `!' supposed to be there?   Looks odd.
> 
Fixed in the patch below.

> d) How did this happen?
> 
>    int tpm_pm_suspend(struct device *dev, pm_message_t pm_state, u32 level)
> 
>    device_driver.suspend() only takes two arguments nowadays.
> 
> 
> e)
> 
> 	int tpm_pm_resume(struct device *dev, u32 level)
> 
>    Ditto
> 

>

Signed-off-by: Kylene Hall <kjhall@us.ibm.com>
---
--- linux-2.6.14/drivers/char/tpm/tpm.c.orig	2005-11-11 14:08:48.000000000 -0600
+++ linux-2.6.14/drivers/char/tpm/tpm.c	2005-11-11 14:09:47.000000000
-0600
@@ -428,8 +428,7 @@ ssize_t tpm_read(struct file * file, cha
 			ret_size = size;
 
 		down(&chip->buffer_mutex);
-		if (copy_to_user
-		    ((void __user *) buf, chip->data_buffer, ret_size))
+		if (copy_to_user(buf, chip->data_buffer, ret_size))
 			ret_size = -EFAULT;
 		up(&chip->buffer_mutex);
 	}
@@ -460,7 +459,7 @@ void tpm_remove_hardware(struct device *
 	sysfs_remove_group(&dev->kobj, chip->vendor->attr_group);
 
 	dev_mask[chip->dev_num / TPM_NUM_MASK_ENTRIES ] &=
-		!(1 << (chip->dev_num % TPM_NUM_MASK_ENTRIES));
+		~(1 << (chip->dev_num % TPM_NUM_MASK_ENTRIES));
 
 	kfree(chip);
 



  parent reply	other threads:[~2005-11-11 20:10 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-10-26 17:11 [PATCH] Infineon TPM: move infineon driver off pci_dev Marcel Selhorst
2005-10-26 17:23 ` Kylene Jo Hall
2005-10-26 17:41 ` matthieu castet
2005-10-26 19:53   ` Marcel Selhorst
2005-10-27 11:22   ` Marcel Selhorst
2005-10-27 14:07     ` Kylene Jo Hall
2005-10-27 21:55       ` Andrew Morton
2005-10-27 22:03         ` Roland Dreier
2005-10-27 22:26           ` Andrew Morton
2005-10-28 14:22             ` Kylene Jo Hall
2005-11-11 20:11         ` Kylene Jo Hall [this message]
2005-11-11 23:08           ` [PATCH] TPM: cleanups Kylene Jo Hall
2005-11-12 21:48             ` Andrew Morton
2005-11-16 22:48               ` Kylene Jo Hall
2005-10-27 21:33     ` [PATCH] Infineon TPM: move infineon driver off pci_dev Andrew Morton
2005-10-28  5:23       ` Marcel Selhorst
2005-10-27 21:42     ` matthieu castet

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=1131739863.5048.18.camel@localhost.localdomain \
    --to=kjhall@us.ibm.com \
    --cc=akpm@osdl.org \
    --cc=castet.matthieu@free.fr \
    --cc=linux-kernel@vger.kernel.org \
    --cc=selhorst@crypto.rub.de \
    /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

Powered by JetHome