Received: by 2002:a89:48b:0:b0:1f5:f2ab:c469 with SMTP id a11csp520430lqd; Wed, 24 Apr 2024 09:03:16 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWDalbpirGtUoll8EaXgGPWLdVB/afD0Ik8zP9+1hL7iq2nqblQ9lBJMwWfSYRUiDX5tvhi3DgyRCpIsopjNgq1rP2JT0nTGo83s4zssA== X-Google-Smtp-Source: AGHT+IHSH+lFeLaTYTxG/Xy46cuCTLSjqpIuYHCWnRpXyJRsClE9khuKHsLzYr6/HROsbZH9bmT8 X-Received: by 2002:a05:6870:a413:b0:22e:96a0:201c with SMTP id m19-20020a056870a41300b0022e96a0201cmr2888498oal.35.1713974596273; Wed, 24 Apr 2024 09:03:16 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713974596; cv=pass; d=google.com; s=arc-20160816; b=YP+TEL+SFGzmeAKP9eLfGoQFc1giWOARGU5DzNRJWn2KySEPzPl4NptnZrlZhpA9PN jFP5H7hMOYfW5vx+1hvyiOeBaiv+YrCu1EpfRFSJvfMCbregzBHhdm48+QwpYePZQKkI ivpNEQkrjDgYRq/DSjt3ly8vUHZGGAxr3XDt1HAcn0YKjHxdcEoC1H7ORxrTvXzurneR GyBZtnB07MsbgluavEI2oNDNUgUCQsp9cjovChX1d6pKHEwG1unRnIPK3YvY10Ni2LC7 xbsiltBy+nhIUoreWYREBMCKpBEG4T2v/aU5dSl0LAKGa4GR58kayKHX/ke8ixqc/5xq zckA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:user-agent:date:message-id:from :references:cc:to:subject; bh=3IC+wrHzd7yYg9F1wCEBJvJOUn5TUEWhhnHa7k1HrEw=; fh=rA7Y7clfXLcOAS3irJQlNWdjsdcgan8olAHgehpLekk=; b=0hMTe8GaMQORsNhFZ2jgw4QY0fh0mGnHPdDx4AYLhCsuvS15mpcNkLr/tja+tJwF10 hZc4T1xBr3F3qZXVr4e6L9JFm/52WQxZ/GXugi07FmiXuVbgyp8sRkP5hsfZgZ5pVP5A PN7wv+aam+E47GLQ3LoE+zfwVmA9xdUmD2l61URP0KxmsqAmh7WwM48gAYg4aLbV9sCi +P0zc8fnWCRC7mCpULijENH7zoQsXnI8gfmm3fj+vXS3W9Y0CYqTzrVwCXFuDcmvUycV nCkoSIx4r8eL5o/roi4ycmlQw3gcuAxB4VcKmBWdg224mcdnq31yDzSNAKLtcUOKOiA4 A62g==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=easystack.cn dmarc=pass fromdomain=easystack.cn); spf=pass (google.com: domain of linux-kernel+bounces-157251-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-157251-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=easystack.cn Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id h191-20020a6383c8000000b00604b87e10f6si2095178pge.544.2024.04.24.09.03.15 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Apr 2024 09:03:16 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-157251-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=easystack.cn dmarc=pass fromdomain=easystack.cn); spf=pass (google.com: domain of linux-kernel+bounces-157251-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-157251-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=easystack.cn Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id DF09B281646 for ; Wed, 24 Apr 2024 15:53:08 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 369E0161911; Wed, 24 Apr 2024 15:52:53 +0000 (UTC) Received: from mail-m12824.netease.com (mail-m12824.netease.com [103.209.128.24]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 129C11422AF; Wed, 24 Apr 2024 15:52:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.209.128.24 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713973972; cv=none; b=aQoS/t/eF4oSymBar1BGn/3S/FB7iqiiIchXFj83Osme9Eeo+MHsLScYKVpQeDfacejtb3ybTgswEJeLUh/25Isf8+wTVt5/gythGeIxQornJ7Q3X62wY9dnQJy+MfqTlYG4BSolo3b5V4XY+ld/R0esNwA8jL2AIW7z6Srl8kY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713973972; c=relaxed/simple; bh=qOuZ/FKAj56jtkFL4SdM4vCiYPbiiMS+JV1peJ4ZbiY=; h=Subject:To:Cc:References:From:Message-ID:Date:MIME-Version: In-Reply-To:Content-Type; b=s6/e9+UX1HQUzlpJ7kL1v1dZEPMgmRMqWH5e/CpeJEIFUkLaHhDXrpsaw5NaVAsPXSCGaIUZ4mr+QJdbtpJbPnKktsMbCWAD7uuBy8HuDBFdBFOCefCamNyjuVjx7lA06KSAbmAKfGvpEuKZEByIrV1CEkQebeAhTB3lQXAIpyk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=easystack.cn; spf=pass smtp.mailfrom=easystack.cn; arc=none smtp.client-ip=103.209.128.24 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=easystack.cn Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=easystack.cn Received: from [192.168.122.189] (unknown [218.94.118.90]) by smtp.qiye.163.com (Hmail) with ESMTPA id C5A03860120; Wed, 24 Apr 2024 16:43:48 +0800 (CST) Subject: Re: [PATCH 2/7] cbd: introduce cbd_transport To: Chaitanya Kulkarni , "dan.j.williams@intel.com" , "axboe@kernel.dk" Cc: "linux-block@vger.kernel.org" , "linux-kernel@vger.kernel.org" , "linux-cxl@vger.kernel.org" , Dongsheng Yang References: <20240422071606.52637-1-dongsheng.yang@easystack.cn> <20240422071606.52637-3-dongsheng.yang@easystack.cn> <780f3ccd-5112-4948-81c3-3144c6779503@nvidia.com> From: Dongsheng Yang Message-ID: <7ec61a75-79ec-94db-ebf9-58679c85edeb@easystack.cn> Date: Wed, 24 Apr 2024 16:43:47 +0800 User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.4.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 In-Reply-To: <780f3ccd-5112-4948-81c3-3144c6779503@nvidia.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit X-HM-Spam-Status: e1kfGhgUHx5ZQUpXWQgPGg8OCBgUHx5ZQUlOS1dZFg8aDwILHllBWSg2Ly tZV1koWUFJQjdXWS1ZQUlXWQ8JGhUIEh9ZQVkZTE1LVkxISElJGE9MSkJDH1UZERMWGhIXJBQOD1 lXWRgSC1lBWUlKQ1VCT1VKSkNVQktZV1kWGg8SFR0UWUFZT0tIVUpNT0lMTlVKS0tVSkJLS1kG X-HM-Tid: 0a8f0f467de2023ckunmc5a03860120 X-HM-MType: 1 X-HM-Sender-Digest: e1kMHhlZQR0aFwgeV1kSHx4VD1lBWUc6MTI6Iww6Ojc1ThACPToJAgMC LxpPFChVSlVKTEpIQk9DSUlCTk9JVTMWGhIXVR8UFRwIEx4VHFUCGhUcOx4aCAIIDxoYEFUYFUVZ V1kSC1lBWUlKQ1VCT1VKSkNVQktZV1kIAVlBT09NSjcG 在 2024/4/24 星期三 下午 12:08, Chaitanya Kulkarni 写道: >> +static ssize_t cbd_myhost_show(struct device *dev, >> + struct device_attribute *attr, >> + char *buf) >> +{ >> + struct cbd_transport *cbdt; >> + struct cbd_host *host; >> + >> + cbdt = container_of(dev, struct cbd_transport, device); >> + >> + host = cbdt->host; >> + if (!host) >> + return 0; >> + >> + return sprintf(buf, "%d\n", host->host_id); > > snprintf() ? IMO, it will only print a decimal unsigned int, so it shouldn't overflow the buffer. > >> +} >> + >> +static DEVICE_ATTR(my_host_id, 0400, cbd_myhost_show, NULL); >> + >> +enum { > > [...] > >> + >> +static ssize_t cbd_adm_store(struct device *dev, >> + struct device_attribute *attr, >> + const char *ubuf, >> + size_t size) >> +{ >> + int ret; >> + char *buf; >> + struct cbd_adm_options opts = { 0 }; >> + struct cbd_transport *cbdt; >> + > > reverse tree order that matches rest of your code ? Agreed, > >> + if (!capable(CAP_SYS_ADMIN)) >> + return -EPERM; >> + >> + cbdt = container_of(dev, struct cbd_transport, device); >> + >> + buf = kmemdup(ubuf, size + 1, GFP_KERNEL); >> + if (IS_ERR(buf)) { >> + pr_err("failed to dup buf for adm option: %d", (int)PTR_ERR(buf)); >> + return PTR_ERR(buf); >> + } >> + buf[size] = '\0'; >> + ret = parse_adm_options(cbdt, buf, &opts); >> + if (ret < 0) { >> + kfree(buf); >> + return ret; >> + } >> + kfree(buf); >> + > > standard format is using goto out and having only on kfree() > at the end of the function ... Okey, having a unified error handling path is a good idea, and it's suitable here as well, thanx. > >> + switch (opts.op) { >> + case CBDT_ADM_OP_B_START: >> + break; >> + case CBDT_ADM_OP_B_STOP: >> + break; >> + case CBDT_ADM_OP_B_CLEAR: >> + break; >> + case CBDT_ADM_OP_DEV_START: >> + break; >> + case CBDT_ADM_OP_DEV_STOP: >> + break; >> + default: >> + pr_err("invalid op: %d\n", opts.op); >> + return -EINVAL; >> + } >> + >> + if (ret < 0) >> + return ret; >> + >> + return size; >> +} >> + > > [...] > >> +static struct cbd_transport *cbdt_alloc(void) >> +{ >> + struct cbd_transport *cbdt; >> + int ret; >> + >> + cbdt = kzalloc(sizeof(struct cbd_transport), GFP_KERNEL); >> + if (!cbdt) { >> + return NULL; >> + } > > no braces needed for single statements in if ... applies rest of > the code ... thanx, Iwill remove unnecessary braces next version. > > -ck > >