Skip to content

Commit 233a065

Browse files
jgunthorpeJarkko Sakkinen
authored andcommitted
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: 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>
1 parent c2e514d commit 233a065

File tree

13 files changed

+89
-93
lines changed

13 files changed

+89
-93
lines changed

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
}
@@ -113,13 +113,11 @@ struct tpm_chip *tpmm_chip_alloc(struct device *dev,
113113

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

116-
chip->pdev = dev;
117-
118116
dev_set_drvdata(dev, chip);
119117

120118
chip->dev.class = tpm_class;
121119
chip->dev.release = tpm_dev_release;
122-
chip->dev.parent = chip->pdev;
120+
chip->dev.parent = dev;
123121
#ifdef CONFIG_ACPI
124122
chip->dev.groups = chip->groups;
125123
#endif
@@ -134,7 +132,7 @@ struct tpm_chip *tpmm_chip_alloc(struct device *dev,
134132
device_initialize(&chip->dev);
135133

136134
cdev_init(&chip->cdev, &tpm_fops);
137-
chip->cdev.owner = chip->pdev->driver->owner;
135+
chip->cdev.owner = dev->driver->owner;
138136
chip->cdev.kobj.parent = &chip->dev.kobj;
139137

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

243241
if (!(chip->flags & TPM_CHIP_FLAG_TPM2)) {
244-
rc = __compat_only_sysfs_link_entry_to_kobj(&chip->pdev->kobj,
245-
&chip->dev.kobj,
246-
"ppi");
242+
rc = __compat_only_sysfs_link_entry_to_kobj(
243+
&chip->dev.parent->kobj, &chip->dev.kobj, "ppi");
247244
if (rc && rc != -ENOENT) {
248245
tpm_chip_unregister(chip);
249246
return rc;
@@ -278,7 +275,7 @@ void tpm_chip_unregister(struct tpm_chip *chip)
278275
synchronize_rcu();
279276

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

283280
tpm1_chip_unregister(chip);
284281
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
@@ -345,7 +345,7 @@ ssize_t tpm_transmit(struct tpm_chip *chip, const char *buf,
345345
if (count == 0)
346346
return -ENODATA;
347347
if (count > bufsiz) {
348-
dev_err(chip->pdev,
348+
dev_err(&chip->dev,
349349
"invalid count value %x %zx\n", count, bufsiz);
350350
return -E2BIG;
351351
}
@@ -354,7 +354,7 @@ ssize_t tpm_transmit(struct tpm_chip *chip, const char *buf,
354354

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

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

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

390390
out_recv:
391391
rc = chip->ops->recv(chip, (u8 *) buf, bufsiz);
392392
if (rc < 0)
393-
dev_err(chip->pdev,
393+
dev_err(&chip->dev,
394394
"tpm_transmit: tpm_recv: error %zd\n", rc);
395395
out:
396396
mutex_unlock(&chip->tpm_mutex);
@@ -416,7 +416,7 @@ ssize_t tpm_transmit_cmd(struct tpm_chip *chip, 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;
@@ -527,7 +527,7 @@ int tpm_get_timeouts(struct tpm_chip *chip)
527527
if (rc == TPM_ERR_INVALID_POSTINIT) {
528528
/* The TPM is not started, we are the first to talk to it.
529529
Execute a startup command. */
530-
dev_info(chip->pdev, "Issuing TPM_STARTUP");
530+
dev_info(&chip->dev, "Issuing TPM_STARTUP");
531531
if (tpm_startup(chip, TPM_ST_CLEAR))
532532
return rc;
533533

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

579579
/* Report adjusted timeouts */
580580
if (chip->vendor.timeout_adjusted) {
581-
dev_info(chip->pdev,
581+
dev_info(&chip->dev,
582582
HW_ERR "Adjusting reported timeouts: A %lu->%luus B %lu->%luus C %lu->%luus D %lu->%luus\n",
583583
old_timeout[0], new_timeout[0],
584584
old_timeout[1], new_timeout[1],
@@ -625,7 +625,7 @@ int tpm_get_timeouts(struct tpm_chip *chip)
625625
chip->vendor.duration[TPM_MEDIUM] *= 1000;
626626
chip->vendor.duration[TPM_LONG] *= 1000;
627627
chip->vendor.duration_adjusted = true;
628-
dev_info(chip->pdev, "Adjusting TPM timeout parameters.");
628+
dev_info(&chip->dev, "Adjusting TPM timeout parameters.");
629629
}
630630
return 0;
631631
}
@@ -815,7 +815,9 @@ int tpm_do_selftest(struct tpm_chip *chip)
815815
* around 300ms while the self test is ongoing, keep trying
816816
* until the self test duration expires. */
817817
if (rc == -ETIME) {
818-
dev_info(chip->pdev, HW_ERR "TPM command timed out during continue self test");
818+
dev_info(
819+
&chip->dev, HW_ERR
820+
"TPM command timed out during continue self test");
819821
msleep(delay_msec);
820822
continue;
821823
}
@@ -825,7 +827,7 @@ int tpm_do_selftest(struct tpm_chip *chip)
825827

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

980982
if (rc)
981-
dev_err(chip->pdev,
983+
dev_err(&chip->dev,
982984
"Error (%d) sending savestate before suspend\n", rc);
983985
else if (try > 0)
984-
dev_warn(chip->pdev, "TPM savestate took %dms\n",
986+
dev_warn(&chip->dev, "TPM savestate took %dms\n",
985987
try * TPM_TIMEOUT_RETRY);
986988

987989
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
@@ -167,7 +167,6 @@ enum tpm_chip_flags {
167167
};
168168

169169
struct tpm_chip {
170-
struct device *pdev; /* Device stuff */
171170
struct device dev;
172171
struct cdev cdev;
173172

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

200199
static inline void tpm_chip_put(struct tpm_chip *chip)
201200
{
202-
module_put(chip->pdev->driver->owner);
201+
module_put(chip->dev.parent->driver->owner);
203202
}
204203

205204
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
@@ -597,7 +597,7 @@ static void tpm2_flush_context(struct tpm_chip *chip, u32 handle)
597597

598598
rc = tpm_buf_init(&buf, TPM2_ST_NO_SESSIONS, TPM2_CC_FLUSH_CONTEXT);
599599
if (rc) {
600-
dev_warn(chip->pdev, "0x%08x was not flushed, out of memory\n",
600+
dev_warn(&chip->dev, "0x%08x was not flushed, out of memory\n",
601601
handle);
602602
return;
603603
}
@@ -606,7 +606,7 @@ static void tpm2_flush_context(struct tpm_chip *chip, u32 handle)
606606

607607
rc = tpm_transmit_cmd(chip, buf.data, PAGE_SIZE, "flushing context");
608608
if (rc)
609-
dev_warn(chip->pdev, "0x%08x was not flushed, rc=%d\n", handle,
609+
dev_warn(&chip->dev, "0x%08x was not flushed, rc=%d\n", handle,
610610
rc);
611611

612612
tpm_buf_destroy(&buf);
@@ -770,7 +770,7 @@ void tpm2_shutdown(struct tpm_chip *chip, u16 shutdown_type)
770770
* except print the error code on a system failure.
771771
*/
772772
if (rc < 0)
773-
dev_warn(chip->pdev, "transmit returned %d while stopping the TPM",
773+
dev_warn(&chip->dev, "transmit returned %d while stopping the TPM",
774774
rc);
775775
}
776776
EXPORT_SYMBOL_GPL(tpm2_shutdown);
@@ -837,7 +837,7 @@ static int tpm2_start_selftest(struct tpm_chip *chip, bool full)
837837
* immediately. This is a workaround for that.
838838
*/
839839
if (rc == TPM2_RC_TESTING) {
840-
dev_warn(chip->pdev, "Got RC_TESTING, ignoring\n");
840+
dev_warn(&chip->dev, "Got RC_TESTING, ignoring\n");
841841
rc = 0;
842842
}
843843

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)