From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752155AbbIHSnC (ORCPT ); Tue, 8 Sep 2015 14:43:02 -0400 Received: from youngberry.canonical.com ([91.189.89.112]:48660 "EHLO youngberry.canonical.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750911AbbIHSnB (ORCPT ); Tue, 8 Sep 2015 14:43:01 -0400 From: Luis Henriques To: Minchan Kim , Nitin Gupta , Sergey Senozhatsky Cc: Andrew Morton , linux-kernel@vger.kernel.org Subject: [PATCH v2] zram: introduce comp algorithm fallback functionality Date: Tue, 8 Sep 2015 19:42:56 +0100 Message-Id: <1441737776-25280-1-git-send-email-luis.henriques@canonical.com> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When the user supplies an unsupported compression algorithm, keep the previously selected one (knowingly supported) or the default one (if the compression algorithm hasn't been changed yet). Note that previously this operation (i.e. setting an invalid algorithm) would result in no algorithm being selected, which means that this represents a small change in the default behaviour. Cc: Sergey Senozhatsky Signed-off-by: Luis Henriques --- Changes since v1: * Moved the algorithm check further up, before mutex lock * Dropped error path refactoring * Updated commit text to explicitly refer to the ABI change (changes suggested by Sergey and Minchan) drivers/block/zram/zram_drv.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c index 9c01f5bfa33f..1caa8f793e51 100644 --- a/drivers/block/zram/zram_drv.c +++ b/drivers/block/zram/zram_drv.c @@ -365,6 +365,9 @@ static ssize_t comp_algorithm_store(struct device *dev, struct zram *zram = dev_to_zram(dev); size_t sz; + if (!zcomp_available_algorithm(buf)) + return -EINVAL; + down_write(&zram->init_lock); if (init_done(zram)) { up_write(&zram->init_lock); @@ -378,9 +381,6 @@ static ssize_t comp_algorithm_store(struct device *dev, if (sz > 0 && zram->compressor[sz - 1] == '\n') zram->compressor[sz - 1] = 0x00; - if (!zcomp_available_algorithm(zram->compressor)) - len = -EINVAL; - up_write(&zram->init_lock); return len; }