Skip to content

Commit 5e07de5

Browse files
jgunthorpegregkh
authored andcommitted
tpm: Get rid of chip->pdev
commit 8cfffc9d4d3786d3b496a021d7224e06328bac7d upstream. 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: Jason Gunthorpe <jgunthorpe@obsidianresearch.com> Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com> Tested-by: Stefan Berger <stefanb@linux.vnet.ibm.com> Reviewed-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com> Tested-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com> Signed-off-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent a2e0b1c commit 5e07de5

13 files changed

Lines changed: 89 additions & 93 deletions

drivers/char/tpm/tpm-chip.c

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ struct tpm_chip *tpm_chip_find_get(int chip_num)
4949
if (chip_num != TPM_ANY_NUM && chip_num != pos->dev_num)
5050
continue;
5151

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

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

115-
chip->pdev = dev;
116-
117115
dev_set_drvdata(dev, chip);
118116

119117
chip->dev.class = tpm_class;
120118
chip->dev.release = tpm_dev_release;
121-
chip->dev.parent = chip->pdev;
119+
chip->dev.parent = dev;
122120
#ifdef CONFIG_ACPI
123121
chip->dev.groups = chip->groups;
124122
#endif
@@ -133,7 +131,7 @@ struct tpm_chip *tpmm_chip_alloc(struct device *dev,
133131
device_initialize(&chip->dev);
134132

135133
cdev_init(&chip->cdev, &tpm_fops);
136-
chip->cdev.owner = chip->pdev->driver->owner;
134+
chip->cdev.owner = dev->driver->owner;
137135
chip->cdev.kobj.parent = &chip->dev.kobj;
138136

139137
devm_add_action(dev, (void (*)(void *)) put_device, &chip->dev);
@@ -236,9 +234,8 @@ int tpm_chip_register(struct tpm_chip *chip)
236234
chip->flags |= TPM_CHIP_FLAG_REGISTERED;
237235

238236
if (!(chip->flags & TPM_CHIP_FLAG_TPM2)) {
239-
rc = __compat_only_sysfs_link_entry_to_kobj(&chip->pdev->kobj,
240-
&chip->dev.kobj,
241-
"ppi");
237+
rc = __compat_only_sysfs_link_entry_to_kobj(
238+
&chip->dev.parent->kobj, &chip->dev.kobj, "ppi");
242239
if (rc && rc != -ENOENT) {
243240
tpm_chip_unregister(chip);
244241
return rc;
@@ -273,7 +270,7 @@ void tpm_chip_unregister(struct tpm_chip *chip)
273270
synchronize_rcu();
274271

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

278275
tpm1_chip_unregister(chip);
279276
tpm_del_char_device(chip);

drivers/char/tpm/tpm-dev.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ static int tpm_open(struct inode *inode, struct file *file)
6161
* by the check of is_open variable, which is protected
6262
* by driver_lock. */
6363
if (test_and_set_bit(0, &chip->is_open)) {
64-
dev_dbg(chip->pdev, "Another process owns this TPM\n");
64+
dev_dbg(&chip->dev, "Another process owns this TPM\n");
6565
return -EBUSY;
6666
}
6767

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

8181
file->private_data = priv;
82-
get_device(chip->pdev);
8382
return 0;
8483
}
8584

@@ -166,7 +165,6 @@ static int tpm_release(struct inode *inode, struct file *file)
166165
file->private_data = NULL;
167166
atomic_set(&priv->data_pending, 0);
168167
clear_bit(0, &priv->chip->is_open);
169-
put_device(priv->chip->pdev);
170168
kfree(priv);
171169
return 0;
172170
}

drivers/char/tpm/tpm-interface.c

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@ ssize_t tpm_transmit(struct tpm_chip *chip, const u8 *buf, size_t bufsiz,
343343
if (count == 0)
344344
return -ENODATA;
345345
if (count > bufsiz) {
346-
dev_err(chip->pdev,
346+
dev_err(&chip->dev,
347347
"invalid count value %x %zx\n", count, bufsiz);
348348
return -E2BIG;
349349
}
@@ -353,7 +353,7 @@ ssize_t tpm_transmit(struct tpm_chip *chip, const u8 *buf, size_t bufsiz,
353353

354354
rc = chip->ops->send(chip, (u8 *) buf, count);
355355
if (rc < 0) {
356-
dev_err(chip->pdev,
356+
dev_err(&chip->dev,
357357
"tpm_transmit: tpm_send: error %zd\n", rc);
358358
goto out;
359359
}
@@ -372,7 +372,7 @@ ssize_t tpm_transmit(struct tpm_chip *chip, const u8 *buf, size_t bufsiz,
372372
goto out_recv;
373373

374374
if (chip->ops->req_canceled(chip, status)) {
375-
dev_err(chip->pdev, "Operation Canceled\n");
375+
dev_err(&chip->dev, "Operation Canceled\n");
376376
rc = -ECANCELED;
377377
goto out;
378378
}
@@ -382,14 +382,14 @@ ssize_t tpm_transmit(struct tpm_chip *chip, const u8 *buf, size_t bufsiz,
382382
} while (time_before(jiffies, stop));
383383

384384
chip->ops->cancel(chip);
385-
dev_err(chip->pdev, "Operation Timed out\n");
385+
dev_err(&chip->dev, "Operation Timed out\n");
386386
rc = -ETIME;
387387
goto out;
388388

389389
out_recv:
390390
rc = chip->ops->recv(chip, (u8 *) buf, bufsiz);
391391
if (rc < 0)
392-
dev_err(chip->pdev,
392+
dev_err(&chip->dev,
393393
"tpm_transmit: tpm_recv: error %zd\n", rc);
394394
out:
395395
if (!(flags & TPM_TRANSMIT_UNLOCKED))
@@ -416,7 +416,7 @@ ssize_t tpm_transmit_cmd(struct tpm_chip *chip, const void *cmd,
416416

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

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

@@ -526,7 +526,7 @@ int tpm_get_timeouts(struct tpm_chip *chip)
526526
0, NULL);
527527
}
528528
if (rc) {
529-
dev_err(chip->pdev,
529+
dev_err(&chip->dev,
530530
"A TPM error (%zd) occurred attempting to determine the timeouts\n",
531531
rc);
532532
goto duration;
@@ -565,7 +565,7 @@ int tpm_get_timeouts(struct tpm_chip *chip)
565565

566566
/* Report adjusted timeouts */
567567
if (chip->vendor.timeout_adjusted) {
568-
dev_info(chip->pdev,
568+
dev_info(&chip->dev,
569569
HW_ERR "Adjusting reported timeouts: A %lu->%luus B %lu->%luus C %lu->%luus D %lu->%luus\n",
570570
old_timeout[0], new_timeout[0],
571571
old_timeout[1], new_timeout[1],
@@ -612,7 +612,7 @@ int tpm_get_timeouts(struct tpm_chip *chip)
612612
chip->vendor.duration[TPM_MEDIUM] *= 1000;
613613
chip->vendor.duration[TPM_LONG] *= 1000;
614614
chip->vendor.duration_adjusted = true;
615-
dev_info(chip->pdev, "Adjusting TPM timeout parameters.");
615+
dev_info(&chip->dev, "Adjusting TPM timeout parameters.");
616616
}
617617
return 0;
618618
}
@@ -802,7 +802,9 @@ int tpm_do_selftest(struct tpm_chip *chip)
802802
* around 300ms while the self test is ongoing, keep trying
803803
* until the self test duration expires. */
804804
if (rc == -ETIME) {
805-
dev_info(chip->pdev, HW_ERR "TPM command timed out during continue self test");
805+
dev_info(
806+
&chip->dev, HW_ERR
807+
"TPM command timed out during continue self test");
806808
msleep(delay_msec);
807809
continue;
808810
}
@@ -812,7 +814,7 @@ int tpm_do_selftest(struct tpm_chip *chip)
812814

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

968970
if (rc)
969-
dev_err(chip->pdev,
971+
dev_err(&chip->dev,
970972
"Error (%d) sending savestate before suspend\n", rc);
971973
else if (try > 0)
972-
dev_warn(chip->pdev, "TPM savestate took %dms\n",
974+
dev_warn(&chip->dev, "TPM savestate took %dms\n",
973975
try * TPM_TIMEOUT_RETRY);
974976

975977
return rc;

drivers/char/tpm/tpm-sysfs.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -284,16 +284,16 @@ static const struct attribute_group tpm_dev_group = {
284284
int tpm_sysfs_add_device(struct tpm_chip *chip)
285285
{
286286
int err;
287-
err = sysfs_create_group(&chip->pdev->kobj,
287+
err = sysfs_create_group(&chip->dev.parent->kobj,
288288
&tpm_dev_group);
289289

290290
if (err)
291-
dev_err(chip->pdev,
291+
dev_err(&chip->dev,
292292
"failed to create sysfs attributes, %d\n", err);
293293
return err;
294294
}
295295

296296
void tpm_sysfs_del_device(struct tpm_chip *chip)
297297
{
298-
sysfs_remove_group(&chip->pdev->kobj, &tpm_dev_group);
298+
sysfs_remove_group(&chip->dev.parent->kobj, &tpm_dev_group);
299299
}

drivers/char/tpm/tpm.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,6 @@ enum tpm_chip_flags {
171171
};
172172

173173
struct tpm_chip {
174-
struct device *pdev; /* Device stuff */
175174
struct device dev;
176175
struct cdev cdev;
177176

@@ -203,7 +202,7 @@ struct tpm_chip {
203202

204203
static inline void tpm_chip_put(struct tpm_chip *chip)
205204
{
206-
module_put(chip->pdev->driver->owner);
205+
module_put(chip->dev.parent->driver->owner);
207206
}
208207

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

drivers/char/tpm/tpm2-cmd.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -570,7 +570,7 @@ static void tpm2_flush_context_cmd(struct tpm_chip *chip, u32 handle,
570570

571571
rc = tpm_buf_init(&buf, TPM2_ST_NO_SESSIONS, TPM2_CC_FLUSH_CONTEXT);
572572
if (rc) {
573-
dev_warn(chip->pdev, "0x%08x was not flushed, out of memory\n",
573+
dev_warn(&chip->dev, "0x%08x was not flushed, out of memory\n",
574574
handle);
575575
return;
576576
}
@@ -580,7 +580,7 @@ static void tpm2_flush_context_cmd(struct tpm_chip *chip, u32 handle,
580580
rc = tpm_transmit_cmd(chip, buf.data, PAGE_SIZE, flags,
581581
"flushing context");
582582
if (rc)
583-
dev_warn(chip->pdev, "0x%08x was not flushed, rc=%d\n", handle,
583+
dev_warn(&chip->dev, "0x%08x was not flushed, rc=%d\n", handle,
584584
rc);
585585

586586
tpm_buf_destroy(&buf);
@@ -753,7 +753,7 @@ void tpm2_shutdown(struct tpm_chip *chip, u16 shutdown_type)
753753
* except print the error code on a system failure.
754754
*/
755755
if (rc < 0)
756-
dev_warn(chip->pdev, "transmit returned %d while stopping the TPM",
756+
dev_warn(&chip->dev, "transmit returned %d while stopping the TPM",
757757
rc);
758758
}
759759
EXPORT_SYMBOL_GPL(tpm2_shutdown);
@@ -820,7 +820,7 @@ static int tpm2_start_selftest(struct tpm_chip *chip, bool full)
820820
* immediately. This is a workaround for that.
821821
*/
822822
if (rc == TPM2_RC_TESTING) {
823-
dev_warn(chip->pdev, "Got RC_TESTING, ignoring\n");
823+
dev_warn(&chip->dev, "Got RC_TESTING, ignoring\n");
824824
rc = 0;
825825
}
826826

drivers/char/tpm/tpm_atmel.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ static int tpm_atml_recv(struct tpm_chip *chip, u8 *buf, size_t count)
4949
for (i = 0; i < 6; i++) {
5050
status = ioread8(chip->vendor.iobase + 1);
5151
if ((status & ATML_STATUS_DATA_AVAIL) == 0) {
52-
dev_err(chip->pdev, "error reading header\n");
52+
dev_err(&chip->dev, "error reading header\n");
5353
return -EIO;
5454
}
5555
*buf++ = ioread8(chip->vendor.iobase);
@@ -60,12 +60,12 @@ static int tpm_atml_recv(struct tpm_chip *chip, u8 *buf, size_t count)
6060
size = be32_to_cpu(*native_size);
6161

6262
if (count < size) {
63-
dev_err(chip->pdev,
63+
dev_err(&chip->dev,
6464
"Recv size(%d) less than available space\n", size);
6565
for (; i < size; i++) { /* clear the waiting data anyway */
6666
status = ioread8(chip->vendor.iobase + 1);
6767
if ((status & ATML_STATUS_DATA_AVAIL) == 0) {
68-
dev_err(chip->pdev, "error reading data\n");
68+
dev_err(&chip->dev, "error reading data\n");
6969
return -EIO;
7070
}
7171
}
@@ -76,7 +76,7 @@ static int tpm_atml_recv(struct tpm_chip *chip, u8 *buf, size_t count)
7676
for (; i < size; i++) {
7777
status = ioread8(chip->vendor.iobase + 1);
7878
if ((status & ATML_STATUS_DATA_AVAIL) == 0) {
79-
dev_err(chip->pdev, "error reading data\n");
79+
dev_err(&chip->dev, "error reading data\n");
8080
return -EIO;
8181
}
8282
*buf++ = ioread8(chip->vendor.iobase);
@@ -86,7 +86,7 @@ static int tpm_atml_recv(struct tpm_chip *chip, u8 *buf, size_t count)
8686
status = ioread8(chip->vendor.iobase + 1);
8787

8888
if (status & ATML_STATUS_DATA_AVAIL) {
89-
dev_err(chip->pdev, "data available is stuck\n");
89+
dev_err(&chip->dev, "data available is stuck\n");
9090
return -EIO;
9191
}
9292

@@ -97,9 +97,9 @@ static int tpm_atml_send(struct tpm_chip *chip, u8 *buf, size_t count)
9797
{
9898
int i;
9999

100-
dev_dbg(chip->pdev, "tpm_atml_send:\n");
100+
dev_dbg(&chip->dev, "tpm_atml_send:\n");
101101
for (i = 0; i < count; i++) {
102-
dev_dbg(chip->pdev, "%d 0x%x(%d)\n", i, buf[i], buf[i]);
102+
dev_dbg(&chip->dev, "%d 0x%x(%d)\n", i, buf[i], buf[i]);
103103
iowrite8(buf[i], chip->vendor.iobase);
104104
}
105105

drivers/char/tpm/tpm_i2c_atmel.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ struct priv_data {
5252
static int i2c_atmel_send(struct tpm_chip *chip, u8 *buf, size_t len)
5353
{
5454
struct priv_data *priv = chip->vendor.priv;
55-
struct i2c_client *client = to_i2c_client(chip->pdev);
55+
struct i2c_client *client = to_i2c_client(chip->dev.parent);
5656
s32 status;
5757

5858
priv->len = 0;
@@ -62,7 +62,7 @@ static int i2c_atmel_send(struct tpm_chip *chip, u8 *buf, size_t len)
6262

6363
status = i2c_master_send(client, buf, len);
6464

65-
dev_dbg(chip->pdev,
65+
dev_dbg(&chip->dev,
6666
"%s(buf=%*ph len=%0zx) -> sts=%d\n", __func__,
6767
(int)min_t(size_t, 64, len), buf, len, status);
6868
return status;
@@ -71,7 +71,7 @@ static int i2c_atmel_send(struct tpm_chip *chip, u8 *buf, size_t len)
7171
static int i2c_atmel_recv(struct tpm_chip *chip, u8 *buf, size_t count)
7272
{
7373
struct priv_data *priv = chip->vendor.priv;
74-
struct i2c_client *client = to_i2c_client(chip->pdev);
74+
struct i2c_client *client = to_i2c_client(chip->dev.parent);
7575
struct tpm_output_header *hdr =
7676
(struct tpm_output_header *)priv->buffer;
7777
u32 expected_len;
@@ -88,7 +88,7 @@ static int i2c_atmel_recv(struct tpm_chip *chip, u8 *buf, size_t count)
8888
return -ENOMEM;
8989

9090
if (priv->len >= expected_len) {
91-
dev_dbg(chip->pdev,
91+
dev_dbg(&chip->dev,
9292
"%s early(buf=%*ph count=%0zx) -> ret=%d\n", __func__,
9393
(int)min_t(size_t, 64, expected_len), buf, count,
9494
expected_len);
@@ -97,7 +97,7 @@ static int i2c_atmel_recv(struct tpm_chip *chip, u8 *buf, size_t count)
9797
}
9898

9999
rc = i2c_master_recv(client, buf, expected_len);
100-
dev_dbg(chip->pdev,
100+
dev_dbg(&chip->dev,
101101
"%s reread(buf=%*ph count=%0zx) -> ret=%d\n", __func__,
102102
(int)min_t(size_t, 64, expected_len), buf, count,
103103
expected_len);
@@ -106,13 +106,13 @@ static int i2c_atmel_recv(struct tpm_chip *chip, u8 *buf, size_t count)
106106

107107
static void i2c_atmel_cancel(struct tpm_chip *chip)
108108
{
109-
dev_err(chip->pdev, "TPM operation cancellation was requested, but is not supported");
109+
dev_err(&chip->dev, "TPM operation cancellation was requested, but is not supported");
110110
}
111111

112112
static u8 i2c_atmel_read_status(struct tpm_chip *chip)
113113
{
114114
struct priv_data *priv = chip->vendor.priv;
115-
struct i2c_client *client = to_i2c_client(chip->pdev);
115+
struct i2c_client *client = to_i2c_client(chip->dev.parent);
116116
int rc;
117117

118118
/* The TPM fails the I2C read until it is ready, so we do the entire
@@ -125,7 +125,7 @@ static u8 i2c_atmel_read_status(struct tpm_chip *chip)
125125
/* Once the TPM has completed the command the command remains readable
126126
* until another command is issued. */
127127
rc = i2c_master_recv(client, priv->buffer, sizeof(priv->buffer));
128-
dev_dbg(chip->pdev,
128+
dev_dbg(&chip->dev,
129129
"%s: sts=%d", __func__, rc);
130130
if (rc <= 0)
131131
return 0;

0 commit comments

Comments
 (0)