| .. | .. |
|---|
| 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) |
|---|
| .. | .. |
|---|
| 43 | 41 | { |
|---|
| 44 | 42 | struct zcrypt_card *zc = to_ap_card(dev)->private; |
|---|
| 45 | 43 | |
|---|
| 46 | | - return snprintf(buf, PAGE_SIZE, "%s\n", zc->type_string); |
|---|
| 44 | + return scnprintf(buf, PAGE_SIZE, "%s\n", zc->type_string); |
|---|
| 47 | 45 | } |
|---|
| 48 | 46 | |
|---|
| 49 | 47 | static DEVICE_ATTR_RO(type); |
|---|
| .. | .. |
|---|
| 52 | 50 | struct device_attribute *attr, |
|---|
| 53 | 51 | char *buf) |
|---|
| 54 | 52 | { |
|---|
| 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; |
|---|
| 56 | 56 | |
|---|
| 57 | | - return snprintf(buf, PAGE_SIZE, "%d\n", zc->online); |
|---|
| 57 | + return scnprintf(buf, PAGE_SIZE, "%d\n", online); |
|---|
| 58 | 58 | } |
|---|
| 59 | 59 | |
|---|
| 60 | 60 | static ssize_t online_store(struct device *dev, |
|---|
| 61 | 61 | struct device_attribute *attr, |
|---|
| 62 | 62 | const char *buf, size_t count) |
|---|
| 63 | 63 | { |
|---|
| 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; |
|---|
| 65 | 66 | struct zcrypt_queue *zq; |
|---|
| 66 | 67 | int online, id; |
|---|
| 67 | 68 | |
|---|
| 68 | 69 | if (sscanf(buf, "%d\n", &online) != 1 || online < 0 || online > 1) |
|---|
| 69 | 70 | return -EINVAL; |
|---|
| 71 | + |
|---|
| 72 | + if (online && !ac->config) |
|---|
| 73 | + return -ENODEV; |
|---|
| 70 | 74 | |
|---|
| 71 | 75 | zc->online = online; |
|---|
| 72 | 76 | id = zc->card->id; |
|---|
| .. | .. |
|---|
| 88 | 92 | { |
|---|
| 89 | 93 | struct zcrypt_card *zc = to_ap_card(dev)->private; |
|---|
| 90 | 94 | |
|---|
| 91 | | - return snprintf(buf, PAGE_SIZE, "%d\n", atomic_read(&zc->load)); |
|---|
| 95 | + return scnprintf(buf, PAGE_SIZE, "%d\n", atomic_read(&zc->load)); |
|---|
| 92 | 96 | } |
|---|
| 93 | 97 | |
|---|
| 94 | 98 | static DEVICE_ATTR_RO(load); |
|---|
| .. | .. |
|---|
| 153 | 157 | { |
|---|
| 154 | 158 | int rc; |
|---|
| 155 | 159 | |
|---|
| 156 | | - rc = sysfs_create_group(&zc->card->ap_dev.device.kobj, |
|---|
| 157 | | - &zcrypt_card_attr_group); |
|---|
| 158 | | - if (rc) |
|---|
| 159 | | - return rc; |
|---|
| 160 | | - |
|---|
| 161 | 160 | spin_lock(&zcrypt_list_lock); |
|---|
| 162 | 161 | list_add_tail(&zc->list, &zcrypt_card_list); |
|---|
| 163 | 162 | spin_unlock(&zcrypt_list_lock); |
|---|
| .. | .. |
|---|
| 165 | 164 | zc->online = 1; |
|---|
| 166 | 165 | |
|---|
| 167 | 166 | 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 | + } |
|---|
| 168 | 175 | |
|---|
| 169 | 176 | return rc; |
|---|
| 170 | 177 | } |
|---|
| .. | .. |
|---|
| 185 | 192 | spin_unlock(&zcrypt_list_lock); |
|---|
| 186 | 193 | sysfs_remove_group(&zc->card->ap_dev.device.kobj, |
|---|
| 187 | 194 | &zcrypt_card_attr_group); |
|---|
| 195 | + zcrypt_card_put(zc); |
|---|
| 188 | 196 | } |
|---|
| 189 | 197 | EXPORT_SYMBOL(zcrypt_card_unregister); |
|---|