Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 8cfffc9d authored by Jason Gunthorpe's avatar Jason Gunthorpe Committed by Jarkko Sakkinen
Browse files

tpm: Get rid of chip->pdev



This is a hold over from before the struct device conversion.

- All prints should be using &chip->dev, which is the Linux
  standard. This changes prints to use tpm0 as the device name,
  not the PnP/etc ID.
- The few places involving sysfs/modules that really do need the
  parent just use chip->dev.parent instead
- We no longer need to get_device(pdev) in any places since it is no
  longer used by any of the code. The kref on the parent is held
  by the device core during device_add and dropped in device_del

Signed-off-by: default avatarJason Gunthorpe <jgunthorpe@obsidianresearch.com>
Signed-off-by: default avatarStefan Berger <stefanb@linux.vnet.ibm.com>
Tested-by: default avatarStefan Berger <stefanb@linux.vnet.ibm.com>
Reviewed-by: default avatarJarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
Tested-by: default avatarJarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
Signed-off-by: default avatarJarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
parent 4d8007ee
Loading
Loading
Loading
Loading
+6 −9
Original line number Original line Diff line number Diff line
@@ -49,7 +49,7 @@ struct tpm_chip *tpm_chip_find_get(int chip_num)
		if (chip_num != TPM_ANY_NUM && chip_num != pos->dev_num)
		if (chip_num != TPM_ANY_NUM && chip_num != pos->dev_num)
			continue;
			continue;


		if (try_module_get(pos->pdev->driver->owner)) {
		if (try_module_get(pos->dev.parent->driver->owner)) {
			chip = pos;
			chip = pos;
			break;
			break;
		}
		}
@@ -113,13 +113,11 @@ struct tpm_chip *tpmm_chip_alloc(struct device *dev,


	scnprintf(chip->devname, sizeof(chip->devname), "tpm%d", chip->dev_num);
	scnprintf(chip->devname, sizeof(chip->devname), "tpm%d", chip->dev_num);


	chip->pdev = dev;

	dev_set_drvdata(dev, chip);
	dev_set_drvdata(dev, chip);


	chip->dev.class = tpm_class;
	chip->dev.class = tpm_class;
	chip->dev.release = tpm_dev_release;
	chip->dev.release = tpm_dev_release;
	chip->dev.parent = chip->pdev;
	chip->dev.parent = dev;
#ifdef CONFIG_ACPI
#ifdef CONFIG_ACPI
	chip->dev.groups = chip->groups;
	chip->dev.groups = chip->groups;
#endif
#endif
@@ -134,7 +132,7 @@ struct tpm_chip *tpmm_chip_alloc(struct device *dev,
	device_initialize(&chip->dev);
	device_initialize(&chip->dev);


	cdev_init(&chip->cdev, &tpm_fops);
	cdev_init(&chip->cdev, &tpm_fops);
	chip->cdev.owner = chip->pdev->driver->owner;
	chip->cdev.owner = dev->driver->owner;
	chip->cdev.kobj.parent = &chip->dev.kobj;
	chip->cdev.kobj.parent = &chip->dev.kobj;


	rc = devm_add_action(dev, (void (*)(void *)) put_device, &chip->dev);
	rc = devm_add_action(dev, (void (*)(void *)) put_device, &chip->dev);
@@ -241,9 +239,8 @@ int tpm_chip_register(struct tpm_chip *chip)
	chip->flags |= TPM_CHIP_FLAG_REGISTERED;
	chip->flags |= TPM_CHIP_FLAG_REGISTERED;


	if (!(chip->flags & TPM_CHIP_FLAG_TPM2)) {
	if (!(chip->flags & TPM_CHIP_FLAG_TPM2)) {
		rc = __compat_only_sysfs_link_entry_to_kobj(&chip->pdev->kobj,
		rc = __compat_only_sysfs_link_entry_to_kobj(
							    &chip->dev.kobj,
		    &chip->dev.parent->kobj, &chip->dev.kobj, "ppi");
							    "ppi");
		if (rc && rc != -ENOENT) {
		if (rc && rc != -ENOENT) {
			tpm_chip_unregister(chip);
			tpm_chip_unregister(chip);
			return rc;
			return rc;
@@ -278,7 +275,7 @@ void tpm_chip_unregister(struct tpm_chip *chip)
	synchronize_rcu();
	synchronize_rcu();


	if (!(chip->flags & TPM_CHIP_FLAG_TPM2))
	if (!(chip->flags & TPM_CHIP_FLAG_TPM2))
		sysfs_remove_link(&chip->pdev->kobj, "ppi");
		sysfs_remove_link(&chip->dev.parent->kobj, "ppi");


	tpm1_chip_unregister(chip);
	tpm1_chip_unregister(chip);
	tpm_del_char_device(chip);
	tpm_del_char_device(chip);
+1 −3
Original line number Original line Diff line number Diff line
@@ -61,7 +61,7 @@ static int tpm_open(struct inode *inode, struct file *file)
	 * by the check of is_open variable, which is protected
	 * by the check of is_open variable, which is protected
	 * by driver_lock. */
	 * by driver_lock. */
	if (test_and_set_bit(0, &chip->is_open)) {
	if (test_and_set_bit(0, &chip->is_open)) {
		dev_dbg(chip->pdev, "Another process owns this TPM\n");
		dev_dbg(&chip->dev, "Another process owns this TPM\n");
		return -EBUSY;
		return -EBUSY;
	}
	}


@@ -79,7 +79,6 @@ static int tpm_open(struct inode *inode, struct file *file)
	INIT_WORK(&priv->work, timeout_work);
	INIT_WORK(&priv->work, timeout_work);


	file->private_data = priv;
	file->private_data = priv;
	get_device(chip->pdev);
	return 0;
	return 0;
}
}


@@ -166,7 +165,6 @@ static int tpm_release(struct inode *inode, struct file *file)
	file->private_data = NULL;
	file->private_data = NULL;
	atomic_set(&priv->data_pending, 0);
	atomic_set(&priv->data_pending, 0);
	clear_bit(0, &priv->chip->is_open);
	clear_bit(0, &priv->chip->is_open);
	put_device(priv->chip->pdev);
	kfree(priv);
	kfree(priv);
	return 0;
	return 0;
}
}
+16 −14
Original line number Original line Diff line number Diff line
@@ -345,7 +345,7 @@ ssize_t tpm_transmit(struct tpm_chip *chip, const char *buf,
	if (count == 0)
	if (count == 0)
		return -ENODATA;
		return -ENODATA;
	if (count > bufsiz) {
	if (count > bufsiz) {
		dev_err(chip->pdev,
		dev_err(&chip->dev,
			"invalid count value %x %zx\n", count, bufsiz);
			"invalid count value %x %zx\n", count, bufsiz);
		return -E2BIG;
		return -E2BIG;
	}
	}
@@ -354,7 +354,7 @@ ssize_t tpm_transmit(struct tpm_chip *chip, const char *buf,


	rc = chip->ops->send(chip, (u8 *) buf, count);
	rc = chip->ops->send(chip, (u8 *) buf, count);
	if (rc < 0) {
	if (rc < 0) {
		dev_err(chip->pdev,
		dev_err(&chip->dev,
			"tpm_transmit: tpm_send: error %zd\n", rc);
			"tpm_transmit: tpm_send: error %zd\n", rc);
		goto out;
		goto out;
	}
	}
@@ -373,7 +373,7 @@ ssize_t tpm_transmit(struct tpm_chip *chip, const char *buf,
			goto out_recv;
			goto out_recv;


		if (chip->ops->req_canceled(chip, status)) {
		if (chip->ops->req_canceled(chip, status)) {
			dev_err(chip->pdev, "Operation Canceled\n");
			dev_err(&chip->dev, "Operation Canceled\n");
			rc = -ECANCELED;
			rc = -ECANCELED;
			goto out;
			goto out;
		}
		}
@@ -383,14 +383,14 @@ ssize_t tpm_transmit(struct tpm_chip *chip, const char *buf,
	} while (time_before(jiffies, stop));
	} while (time_before(jiffies, stop));


	chip->ops->cancel(chip);
	chip->ops->cancel(chip);
	dev_err(chip->pdev, "Operation Timed out\n");
	dev_err(&chip->dev, "Operation Timed out\n");
	rc = -ETIME;
	rc = -ETIME;
	goto out;
	goto out;


out_recv:
out_recv:
	rc = chip->ops->recv(chip, (u8 *) buf, bufsiz);
	rc = chip->ops->recv(chip, (u8 *) buf, bufsiz);
	if (rc < 0)
	if (rc < 0)
		dev_err(chip->pdev,
		dev_err(&chip->dev,
			"tpm_transmit: tpm_recv: error %zd\n", rc);
			"tpm_transmit: tpm_recv: error %zd\n", rc);
out:
out:
	mutex_unlock(&chip->tpm_mutex);
	mutex_unlock(&chip->tpm_mutex);
@@ -416,7 +416,7 @@ ssize_t tpm_transmit_cmd(struct tpm_chip *chip, void *cmd,


	err = be32_to_cpu(header->return_code);
	err = be32_to_cpu(header->return_code);
	if (err != 0 && desc)
	if (err != 0 && desc)
		dev_err(chip->pdev, "A TPM error (%d) occurred %s\n", err,
		dev_err(&chip->dev, "A TPM error (%d) occurred %s\n", err,
			desc);
			desc);


	return err;
	return err;
@@ -527,7 +527,7 @@ int tpm_get_timeouts(struct tpm_chip *chip)
	if (rc == TPM_ERR_INVALID_POSTINIT) {
	if (rc == TPM_ERR_INVALID_POSTINIT) {
		/* The TPM is not started, we are the first to talk to it.
		/* The TPM is not started, we are the first to talk to it.
		   Execute a startup command. */
		   Execute a startup command. */
		dev_info(chip->pdev, "Issuing TPM_STARTUP");
		dev_info(&chip->dev, "Issuing TPM_STARTUP");
		if (tpm_startup(chip, TPM_ST_CLEAR))
		if (tpm_startup(chip, TPM_ST_CLEAR))
			return rc;
			return rc;


@@ -539,7 +539,7 @@ int tpm_get_timeouts(struct tpm_chip *chip)
				  NULL);
				  NULL);
	}
	}
	if (rc) {
	if (rc) {
		dev_err(chip->pdev,
		dev_err(&chip->dev,
			"A TPM error (%zd) occurred attempting to determine the timeouts\n",
			"A TPM error (%zd) occurred attempting to determine the timeouts\n",
			rc);
			rc);
		goto duration;
		goto duration;
@@ -578,7 +578,7 @@ int tpm_get_timeouts(struct tpm_chip *chip)


	/* Report adjusted timeouts */
	/* Report adjusted timeouts */
	if (chip->vendor.timeout_adjusted) {
	if (chip->vendor.timeout_adjusted) {
		dev_info(chip->pdev,
		dev_info(&chip->dev,
			 HW_ERR "Adjusting reported timeouts: A %lu->%luus B %lu->%luus C %lu->%luus D %lu->%luus\n",
			 HW_ERR "Adjusting reported timeouts: A %lu->%luus B %lu->%luus C %lu->%luus D %lu->%luus\n",
			 old_timeout[0], new_timeout[0],
			 old_timeout[0], new_timeout[0],
			 old_timeout[1], new_timeout[1],
			 old_timeout[1], new_timeout[1],
@@ -625,7 +625,7 @@ int tpm_get_timeouts(struct tpm_chip *chip)
		chip->vendor.duration[TPM_MEDIUM] *= 1000;
		chip->vendor.duration[TPM_MEDIUM] *= 1000;
		chip->vendor.duration[TPM_LONG] *= 1000;
		chip->vendor.duration[TPM_LONG] *= 1000;
		chip->vendor.duration_adjusted = true;
		chip->vendor.duration_adjusted = true;
		dev_info(chip->pdev, "Adjusting TPM timeout parameters.");
		dev_info(&chip->dev, "Adjusting TPM timeout parameters.");
	}
	}
	return 0;
	return 0;
}
}
@@ -815,7 +815,9 @@ int tpm_do_selftest(struct tpm_chip *chip)
		 * around 300ms while the self test is ongoing, keep trying
		 * around 300ms while the self test is ongoing, keep trying
		 * until the self test duration expires. */
		 * until the self test duration expires. */
		if (rc == -ETIME) {
		if (rc == -ETIME) {
			dev_info(chip->pdev, HW_ERR "TPM command timed out during continue self test");
			dev_info(
			    &chip->dev, HW_ERR
			    "TPM command timed out during continue self test");
			msleep(delay_msec);
			msleep(delay_msec);
			continue;
			continue;
		}
		}
@@ -825,7 +827,7 @@ int tpm_do_selftest(struct tpm_chip *chip)


		rc = be32_to_cpu(cmd.header.out.return_code);
		rc = be32_to_cpu(cmd.header.out.return_code);
		if (rc == TPM_ERR_DISABLED || rc == TPM_ERR_DEACTIVATED) {
		if (rc == TPM_ERR_DISABLED || rc == TPM_ERR_DEACTIVATED) {
			dev_info(chip->pdev,
			dev_info(&chip->dev,
				 "TPM is disabled/deactivated (0x%X)\n", rc);
				 "TPM is disabled/deactivated (0x%X)\n", rc);
			/* TPM is disabled and/or deactivated; driver can
			/* TPM is disabled and/or deactivated; driver can
			 * proceed and TPM does handle commands for
			 * proceed and TPM does handle commands for
@@ -978,10 +980,10 @@ int tpm_pm_suspend(struct device *dev)
	}
	}


	if (rc)
	if (rc)
		dev_err(chip->pdev,
		dev_err(&chip->dev,
			"Error (%d) sending savestate before suspend\n", rc);
			"Error (%d) sending savestate before suspend\n", rc);
	else if (try > 0)
	else if (try > 0)
		dev_warn(chip->pdev, "TPM savestate took %dms\n",
		dev_warn(&chip->dev, "TPM savestate took %dms\n",
			 try * TPM_TIMEOUT_RETRY);
			 try * TPM_TIMEOUT_RETRY);


	return rc;
	return rc;
+3 −3
Original line number Original line Diff line number Diff line
@@ -284,16 +284,16 @@ static const struct attribute_group tpm_dev_group = {
int tpm_sysfs_add_device(struct tpm_chip *chip)
int tpm_sysfs_add_device(struct tpm_chip *chip)
{
{
	int err;
	int err;
	err = sysfs_create_group(&chip->pdev->kobj,
	err = sysfs_create_group(&chip->dev.parent->kobj,
				 &tpm_dev_group);
				 &tpm_dev_group);


	if (err)
	if (err)
		dev_err(chip->pdev,
		dev_err(&chip->dev,
			"failed to create sysfs attributes, %d\n", err);
			"failed to create sysfs attributes, %d\n", err);
	return err;
	return err;
}
}


void tpm_sysfs_del_device(struct tpm_chip *chip)
void tpm_sysfs_del_device(struct tpm_chip *chip)
{
{
	sysfs_remove_group(&chip->pdev->kobj, &tpm_dev_group);
	sysfs_remove_group(&chip->dev.parent->kobj, &tpm_dev_group);
}
}
+1 −2
Original line number Original line Diff line number Diff line
@@ -167,7 +167,6 @@ enum tpm_chip_flags {
};
};


struct tpm_chip {
struct tpm_chip {
	struct device *pdev;	/* Device stuff */
	struct device dev;
	struct device dev;
	struct cdev cdev;
	struct cdev cdev;


@@ -199,7 +198,7 @@ struct tpm_chip {


static inline void tpm_chip_put(struct tpm_chip *chip)
static inline void tpm_chip_put(struct tpm_chip *chip)
{
{
	module_put(chip->pdev->driver->owner);
	module_put(chip->dev.parent->driver->owner);
}
}


static inline int tpm_read_index(int base, int index)
static inline int tpm_read_index(int base, int index)
Loading