static void zram_debugfs_unregister(struct zram *zram) {};
#endif
+/* Only algo parameter given, lookup by algo name */
+static int lookup_algo_priority(struct zram *zram, const char *algo,
+ u32 min_prio)
+{
+ s32 prio;
+
+ for (prio = min_prio; prio < ZRAM_MAX_COMPS; prio++) {
+ if (!zram->comp_algs[prio])
+ continue;
+
+ if (!strcmp(zram->comp_algs[prio], algo))
+ return prio;
+ }
+
+ return -EINVAL;
+}
+
+/* Both algo and priority parameters given, validate them */
+static int validate_algo_priority(struct zram *zram, const char *algo, u32 prio)
+{
+ if (prio >= ZRAM_MAX_COMPS)
+ return -EINVAL;
+ /* No algo at given priority */
+ if (!zram->comp_algs[prio])
+ return -EINVAL;
+ /* A different algo at given priority */
+ if (strcmp(zram->comp_algs[prio], algo))
+ return -EINVAL;
+ return 0;
+}
+
static void comp_algorithm_set(struct zram *zram, u32 prio, const char *alg)
{
zram->comp_algs[prio] = alg;
char *args, *param, *val, *algo = NULL, *dict_path = NULL;
struct deflate_params deflate_params;
struct zram *zram = dev_to_zram(dev);
+ bool prio_param = false;
int ret;
deflate_params.winbits = ZCOMP_PARAM_NOT_SET;
return -EINVAL;
if (!strcmp(param, "priority")) {
+ prio_param = true;
ret = kstrtoint(val, 10, &prio);
if (ret)
return ret;
if (init_done(zram))
return -EBUSY;
- /* Lookup priority by algorithm name */
- if (algo) {
- s32 p;
-
- prio = -EINVAL;
- for (p = ZRAM_PRIMARY_COMP; p < ZRAM_MAX_COMPS; p++) {
- if (!zram->comp_algs[p])
- continue;
+ if (prio_param) {
+ if (prio < ZRAM_PRIMARY_COMP || prio >= ZRAM_MAX_COMPS)
+ return -EINVAL;
+ }
- if (!strcmp(zram->comp_algs[p], algo)) {
- prio = p;
- break;
- }
- }
+ if (algo && prio_param) {
+ ret = validate_algo_priority(zram, algo, prio);
+ if (ret)
+ return ret;
}
- if (prio < ZRAM_PRIMARY_COMP || prio >= ZRAM_MAX_COMPS)
- return -EINVAL;
+ if (algo && !prio_param) {
+ prio = lookup_algo_priority(zram, algo, ZRAM_PRIMARY_COMP);
+ if (prio < 0)
+ return -EINVAL;
+ }
ret = comp_params_store(zram, prio, level, dict_path, &deflate_params);
return ret ? ret : len;
void *src;
int ret = 0;
- if (!zram->comps[prio])
- return -EINVAL;
-
handle_old = get_slot_handle(zram, index);
if (!handle_old)
return -EINVAL;
char *args, *param, *val, *algo = NULL;
u64 num_recomp_pages = ULLONG_MAX;
struct zram_pp_ctl *ctl = NULL;
- u32 prio = ZRAM_SECONDARY_COMP;
- struct zram_pp_slot *pps;
+ s32 prio = ZRAM_SECONDARY_COMP;
u32 mode = 0, threshold = 0;
+ struct zram_pp_slot *pps;
struct page *page = NULL;
+ bool prio_param = false;
ssize_t ret;
args = skip_spaces(buf);
}
if (!strcmp(param, "priority")) {
- ret = kstrtouint(val, 10, &prio);
+ prio_param = true;
+ ret = kstrtoint(val, 10, &prio);
if (ret)
return ret;
continue;
if (!init_done(zram))
return -EINVAL;
- if (algo) {
- bool found = false;
-
- for (; prio < ZRAM_MAX_COMPS; prio++) {
- if (!zram->comp_algs[prio])
- continue;
-
- if (!strcmp(zram->comp_algs[prio], algo)) {
- found = true;
- break;
- }
- }
+ if (prio_param) {
+ if (prio < ZRAM_SECONDARY_COMP || prio >= ZRAM_MAX_COMPS)
+ return -EINVAL;
+ }
- if (!found) {
- ret = -EINVAL;
- goto out;
- }
+ if (algo && prio_param) {
+ ret = validate_algo_priority(zram, algo, prio);
+ if (ret)
+ return ret;
}
- if (prio < ZRAM_SECONDARY_COMP || prio >= ZRAM_MAX_COMPS) {
- ret = -EINVAL;
- goto out;
+ if (algo && !prio_param) {
+ prio = lookup_algo_priority(zram, algo, ZRAM_SECONDARY_COMP);
+ if (prio < 0)
+ return -EINVAL;
}
+ if (!zram->comps[prio])
+ return -EINVAL;
+
page = alloc_page(GFP_KERNEL);
if (!page) {
ret = -ENOMEM;