From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757286AbbDPL42 (ORCPT ); Thu, 16 Apr 2015 07:56:28 -0400 Received: from mail-pd0-f179.google.com ([209.85.192.179]:34276 "EHLO mail-pd0-f179.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755052AbbDPL4U (ORCPT ); Thu, 16 Apr 2015 07:56:20 -0400 From: Sergey Senozhatsky To: Andrew Morton , Minchan Kim Cc: Nitin Gupta , linux-kernel@vger.kernel.org, Sergey Senozhatsky , Sergey Senozhatsky Subject: [PATCHv2 09/10] zram: return zram device_id value from zram_add() Date: Thu, 16 Apr 2015 20:55:55 +0900 Message-Id: <1429185356-11096-10-git-send-email-sergey.senozhatsky@gmail.com> X-Mailer: git-send-email 2.4.0.rc2 In-Reply-To: <1429185356-11096-1-git-send-email-sergey.senozhatsky@gmail.com> References: <1429185356-11096-1-git-send-email-sergey.senozhatsky@gmail.com> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org zram_add requires valid device_id to be provided, that can be a bit inconvenient. Change zram_add() to return negative value upon new device creation failure, and device_id (>= 0) value otherwise. This prepares zram_add to perform automatic device_id assignment. New device_id will be returned back to user-space (so user can reference that device as /dev/zramX). Signed-off-by: Sergey Senozhatsky --- drivers/block/zram/zram_drv.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c index f26251a..2c2e7cc 100644 --- a/drivers/block/zram/zram_drv.c +++ b/drivers/block/zram/zram_drv.c @@ -1154,6 +1154,10 @@ static struct attribute_group zram_disk_attr_group = { .attrs = zram_disk_attrs, }; +/* + * Allocate and initialize new zram device. the function returns + * '>= 0' device_id upon success, and negative value otherwise. + */ static int zram_add(int device_id) { struct zram *zram; @@ -1241,7 +1245,7 @@ static int zram_add(int device_id) zram->max_comp_streams = 1; pr_info("Added device: %s\n", zram->disk->disk_name); - return 0; + return device_id; out_free_disk: del_gendisk(zram->disk); @@ -1299,7 +1303,7 @@ static int __init zram_init(void) for (dev_id = 0; dev_id < num_devices; dev_id++) { ret = zram_add(dev_id); - if (ret != 0) + if (ret < 0) goto out_error; } -- 2.4.0.rc2