hc
2024-02-20 102a0743326a03cd1a1202ceda21e175b7d3575c
kernel/drivers/s390/crypto/zcrypt_queue.c
....@@ -1,7 +1,5 @@
11 // SPDX-License-Identifier: GPL-2.0+
22 /*
3
- * zcrypt 2.1.0
4
- *
53 * Copyright IBM Corp. 2001, 2012
64 * Author(s): Robert Burroughs
75 * Eric Rossman (edrossma@us.ibm.com)
....@@ -42,22 +40,27 @@
4240 struct device_attribute *attr,
4341 char *buf)
4442 {
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;
4646
47
- return snprintf(buf, PAGE_SIZE, "%d\n", zq->online);
47
+ return scnprintf(buf, PAGE_SIZE, "%d\n", online);
4848 }
4949
5050 static ssize_t online_store(struct device *dev,
5151 struct device_attribute *attr,
5252 const char *buf, size_t count)
5353 {
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;
5556 struct zcrypt_card *zc = zq->zcard;
5657 int online;
5758
5859 if (sscanf(buf, "%d\n", &online) != 1 || online < 0 || online > 1)
5960 return -EINVAL;
6061
62
+ if (online && (!aq->config || !aq->card->config))
63
+ return -ENODEV;
6164 if (online && !zc->online)
6265 return -EINVAL;
6366 zq->online = online;
....@@ -80,7 +83,7 @@
8083 {
8184 struct zcrypt_queue *zq = to_ap_queue(dev)->private;
8285
83
- return snprintf(buf, PAGE_SIZE, "%d\n", atomic_read(&zq->load));
86
+ return scnprintf(buf, PAGE_SIZE, "%d\n", atomic_read(&zq->load));
8487 }
8588
8689 static DEVICE_ATTR_RO(load);
....@@ -109,10 +112,10 @@
109112 zq = kzalloc(sizeof(struct zcrypt_queue), GFP_KERNEL);
110113 if (!zq)
111114 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)
114117 goto out_free;
115
- zq->reply.length = max_response_size;
118
+ zq->reply.len = max_response_size;
116119 INIT_LIST_HEAD(&zq->list);
117120 kref_init(&zq->refcount);
118121 return zq;
....@@ -125,7 +128,7 @@
125128
126129 void zcrypt_queue_free(struct zcrypt_queue *zq)
127130 {
128
- kfree(zq->reply.message);
131
+ kfree(zq->reply.msg);
129132 kfree(zq);
130133 }
131134 EXPORT_SYMBOL(zcrypt_queue_free);
....@@ -177,7 +180,6 @@
177180 &zcrypt_queue_attr_group);
178181 if (rc)
179182 goto out;
180
- get_device(&zq->queue->ap_dev.device);
181183
182184 if (zq->ops->rng) {
183185 rc = zcrypt_rng_device_add();
....@@ -189,7 +191,6 @@
189191 out_unregister:
190192 sysfs_remove_group(&zq->queue->ap_dev.device.kobj,
191193 &zcrypt_queue_attr_group);
192
- put_device(&zq->queue->ap_dev.device);
193194 out:
194195 spin_lock(&zcrypt_list_lock);
195196 list_del_init(&zq->list);
....@@ -217,12 +218,11 @@
217218 list_del_init(&zq->list);
218219 zcrypt_device_count--;
219220 spin_unlock(&zcrypt_list_lock);
220
- zcrypt_card_put(zc);
221221 if (zq->ops->rng)
222222 zcrypt_rng_device_remove();
223223 sysfs_remove_group(&zq->queue->ap_dev.device.kobj,
224224 &zcrypt_queue_attr_group);
225
- put_device(&zq->queue->ap_dev.device);
225
+ zcrypt_card_put(zc);
226226 zcrypt_queue_put(zq);
227227 }
228228 EXPORT_SYMBOL(zcrypt_queue_unregister);