.. | .. |
---|
1 | 1 | // SPDX-License-Identifier: GPL-2.0+ |
---|
2 | 2 | /* |
---|
3 | | - * zcrypt 2.1.0 |
---|
4 | | - * |
---|
5 | 3 | * Copyright IBM Corp. 2001, 2012 |
---|
6 | 4 | * Author(s): Robert Burroughs |
---|
7 | 5 | * Eric Rossman (edrossma@us.ibm.com) |
---|
.. | .. |
---|
42 | 40 | struct device_attribute *attr, |
---|
43 | 41 | char *buf) |
---|
44 | 42 | { |
---|
45 | | - struct zcrypt_queue *zq = to_ap_queue(dev)->private; |
---|
| 43 | + struct ap_queue *aq = to_ap_queue(dev); |
---|
| 44 | + struct zcrypt_queue *zq = aq->private; |
---|
| 45 | + int online = aq->config && zq->online ? 1 : 0; |
---|
46 | 46 | |
---|
47 | | - return snprintf(buf, PAGE_SIZE, "%d\n", zq->online); |
---|
| 47 | + return scnprintf(buf, PAGE_SIZE, "%d\n", online); |
---|
48 | 48 | } |
---|
49 | 49 | |
---|
50 | 50 | static ssize_t online_store(struct device *dev, |
---|
51 | 51 | struct device_attribute *attr, |
---|
52 | 52 | const char *buf, size_t count) |
---|
53 | 53 | { |
---|
54 | | - struct zcrypt_queue *zq = to_ap_queue(dev)->private; |
---|
| 54 | + struct ap_queue *aq = to_ap_queue(dev); |
---|
| 55 | + struct zcrypt_queue *zq = aq->private; |
---|
55 | 56 | struct zcrypt_card *zc = zq->zcard; |
---|
56 | 57 | int online; |
---|
57 | 58 | |
---|
58 | 59 | if (sscanf(buf, "%d\n", &online) != 1 || online < 0 || online > 1) |
---|
59 | 60 | return -EINVAL; |
---|
60 | 61 | |
---|
| 62 | + if (online && (!aq->config || !aq->card->config)) |
---|
| 63 | + return -ENODEV; |
---|
61 | 64 | if (online && !zc->online) |
---|
62 | 65 | return -EINVAL; |
---|
63 | 66 | zq->online = online; |
---|
.. | .. |
---|
80 | 83 | { |
---|
81 | 84 | struct zcrypt_queue *zq = to_ap_queue(dev)->private; |
---|
82 | 85 | |
---|
83 | | - return snprintf(buf, PAGE_SIZE, "%d\n", atomic_read(&zq->load)); |
---|
| 86 | + return scnprintf(buf, PAGE_SIZE, "%d\n", atomic_read(&zq->load)); |
---|
84 | 87 | } |
---|
85 | 88 | |
---|
86 | 89 | static DEVICE_ATTR_RO(load); |
---|
.. | .. |
---|
109 | 112 | zq = kzalloc(sizeof(struct zcrypt_queue), GFP_KERNEL); |
---|
110 | 113 | if (!zq) |
---|
111 | 114 | return NULL; |
---|
112 | | - zq->reply.message = kmalloc(max_response_size, GFP_KERNEL); |
---|
113 | | - if (!zq->reply.message) |
---|
| 115 | + zq->reply.msg = kmalloc(max_response_size, GFP_KERNEL); |
---|
| 116 | + if (!zq->reply.msg) |
---|
114 | 117 | goto out_free; |
---|
115 | | - zq->reply.length = max_response_size; |
---|
| 118 | + zq->reply.len = max_response_size; |
---|
116 | 119 | INIT_LIST_HEAD(&zq->list); |
---|
117 | 120 | kref_init(&zq->refcount); |
---|
118 | 121 | return zq; |
---|
.. | .. |
---|
125 | 128 | |
---|
126 | 129 | void zcrypt_queue_free(struct zcrypt_queue *zq) |
---|
127 | 130 | { |
---|
128 | | - kfree(zq->reply.message); |
---|
| 131 | + kfree(zq->reply.msg); |
---|
129 | 132 | kfree(zq); |
---|
130 | 133 | } |
---|
131 | 134 | EXPORT_SYMBOL(zcrypt_queue_free); |
---|
.. | .. |
---|
177 | 180 | &zcrypt_queue_attr_group); |
---|
178 | 181 | if (rc) |
---|
179 | 182 | goto out; |
---|
180 | | - get_device(&zq->queue->ap_dev.device); |
---|
181 | 183 | |
---|
182 | 184 | if (zq->ops->rng) { |
---|
183 | 185 | rc = zcrypt_rng_device_add(); |
---|
.. | .. |
---|
189 | 191 | out_unregister: |
---|
190 | 192 | sysfs_remove_group(&zq->queue->ap_dev.device.kobj, |
---|
191 | 193 | &zcrypt_queue_attr_group); |
---|
192 | | - put_device(&zq->queue->ap_dev.device); |
---|
193 | 194 | out: |
---|
194 | 195 | spin_lock(&zcrypt_list_lock); |
---|
195 | 196 | list_del_init(&zq->list); |
---|
.. | .. |
---|
217 | 218 | list_del_init(&zq->list); |
---|
218 | 219 | zcrypt_device_count--; |
---|
219 | 220 | spin_unlock(&zcrypt_list_lock); |
---|
220 | | - zcrypt_card_put(zc); |
---|
221 | 221 | if (zq->ops->rng) |
---|
222 | 222 | zcrypt_rng_device_remove(); |
---|
223 | 223 | sysfs_remove_group(&zq->queue->ap_dev.device.kobj, |
---|
224 | 224 | &zcrypt_queue_attr_group); |
---|
225 | | - put_device(&zq->queue->ap_dev.device); |
---|
| 225 | + zcrypt_card_put(zc); |
---|
226 | 226 | zcrypt_queue_put(zq); |
---|
227 | 227 | } |
---|
228 | 228 | EXPORT_SYMBOL(zcrypt_queue_unregister); |
---|