hc
2024-05-10 cde9070d9970eef1f7ec2360586c802a16230ad8
kernel/drivers/s390/crypto/zcrypt_card.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)
....@@ -43,7 +41,7 @@
4341 {
4442 struct zcrypt_card *zc = to_ap_card(dev)->private;
4543
46
- return snprintf(buf, PAGE_SIZE, "%s\n", zc->type_string);
44
+ return scnprintf(buf, PAGE_SIZE, "%s\n", zc->type_string);
4745 }
4846
4947 static DEVICE_ATTR_RO(type);
....@@ -52,21 +50,27 @@
5250 struct device_attribute *attr,
5351 char *buf)
5452 {
55
- struct zcrypt_card *zc = to_ap_card(dev)->private;
53
+ struct ap_card *ac = to_ap_card(dev);
54
+ struct zcrypt_card *zc = ac->private;
55
+ int online = ac->config && zc->online ? 1 : 0;
5656
57
- return snprintf(buf, PAGE_SIZE, "%d\n", zc->online);
57
+ return scnprintf(buf, PAGE_SIZE, "%d\n", online);
5858 }
5959
6060 static ssize_t online_store(struct device *dev,
6161 struct device_attribute *attr,
6262 const char *buf, size_t count)
6363 {
64
- struct zcrypt_card *zc = to_ap_card(dev)->private;
64
+ struct ap_card *ac = to_ap_card(dev);
65
+ struct zcrypt_card *zc = ac->private;
6566 struct zcrypt_queue *zq;
6667 int online, id;
6768
6869 if (sscanf(buf, "%d\n", &online) != 1 || online < 0 || online > 1)
6970 return -EINVAL;
71
+
72
+ if (online && !ac->config)
73
+ return -ENODEV;
7074
7175 zc->online = online;
7276 id = zc->card->id;
....@@ -88,7 +92,7 @@
8892 {
8993 struct zcrypt_card *zc = to_ap_card(dev)->private;
9094
91
- return snprintf(buf, PAGE_SIZE, "%d\n", atomic_read(&zc->load));
95
+ return scnprintf(buf, PAGE_SIZE, "%d\n", atomic_read(&zc->load));
9296 }
9397
9498 static DEVICE_ATTR_RO(load);
....@@ -153,11 +157,6 @@
153157 {
154158 int rc;
155159
156
- rc = sysfs_create_group(&zc->card->ap_dev.device.kobj,
157
- &zcrypt_card_attr_group);
158
- if (rc)
159
- return rc;
160
-
161160 spin_lock(&zcrypt_list_lock);
162161 list_add_tail(&zc->list, &zcrypt_card_list);
163162 spin_unlock(&zcrypt_list_lock);
....@@ -165,6 +164,14 @@
165164 zc->online = 1;
166165
167166 ZCRYPT_DBF(DBF_INFO, "card=%02x register online=1\n", zc->card->id);
167
+
168
+ rc = sysfs_create_group(&zc->card->ap_dev.device.kobj,
169
+ &zcrypt_card_attr_group);
170
+ if (rc) {
171
+ spin_lock(&zcrypt_list_lock);
172
+ list_del_init(&zc->list);
173
+ spin_unlock(&zcrypt_list_lock);
174
+ }
168175
169176 return rc;
170177 }
....@@ -185,5 +192,6 @@
185192 spin_unlock(&zcrypt_list_lock);
186193 sysfs_remove_group(&zc->card->ap_dev.device.kobj,
187194 &zcrypt_card_attr_group);
195
+ zcrypt_card_put(zc);
188196 }
189197 EXPORT_SYMBOL(zcrypt_card_unregister);