Received: by 2002:a25:ef43:0:0:0:0:0 with SMTP id w3csp1527765ybm; Sat, 30 May 2020 11:44:24 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzvRew9r9OOKG8yijpn73sD3WFFrfxWLNZf2Jqz+m4epSSYNS1ahNlSxQFhDtrz6APoA8Vr X-Received: by 2002:a17:906:3441:: with SMTP id d1mr12408686ejb.489.1590864264272; Sat, 30 May 2020 11:44:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1590864264; cv=none; d=google.com; s=arc-20160816; b=PvxjQ82x59GJMLdMxQCWIoMsF7WbjKWplYbNnVakieYwYG55zqhR7gLyKya2Ha1/sC zH1OwROGZfFrz6p8+dYvQ5DYT3gw2hJ5UCzUkyg8moBG75IKnyEtkcPXp88FWQoFK+KA fCnbF9xyLIw9y2XfLVtu8/rXob0j+QNGhqpSi9RutyBJLxsMDxxXW9MK4RkzeOOsOjHL Jwl904xmqd2jE4I0gSj14ORPMMVca1jnTRpBwXWF4szCGjy7BqEvY4m6SatRmBmz4vQA ebngNhAMc2orzeY44+dTqg3m0xJ7RWz3lz+V1lIAknTB7lJtKjoMt7Iwm3ky8kJ13RxI BM3Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:date:cc:to:from:subject:message-id :dkim-signature; bh=YwliNzdV3H/Ve6pKeZGydt7jOsfeEsBTpzoW3tVwaJQ=; b=yF+WtNzORQaSolPDWsfU3OL6LXr1tsnqGPG/tMsIKEq+zTG8kIYXZ4cpvp5Fol3w1y X78nlq5Kg+bMp6psDbL1O+xEVmQarOWWj6zdjDZqoTLBQ3MIIkTn8WlJTy3++Zuqs0Rp Bz3JO4z8x8i9jS/Bgmx6zliumCkicxUsADbVe3A0SNaV5DVRxH9Ah+6W9czRQhY1vU/3 N8z6nVUVWNd/e90U0fGd5i/EXHEKNeYRUrTGu6LKxwcYHULeHS8h6L0HAz6akaqy4MTe /Gs7XIkZ1ISFIFMZxBDKbDvmmhc48elwzyFJu4uYL6+8Tq4QihZd+aNa8kakCr2Fpxxp 7dPQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=lWOOuwFm; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id v15si4768610edq.373.2020.05.30.11.43.25; Sat, 30 May 2020 11:44:24 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=lWOOuwFm; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729212AbgE3Si2 (ORCPT + 99 others); Sat, 30 May 2020 14:38:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49140 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729149AbgE3Si2 (ORCPT ); Sat, 30 May 2020 14:38:28 -0400 Received: from mail-ej1-x641.google.com (mail-ej1-x641.google.com [IPv6:2a00:1450:4864:20::641]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AF06AC03E969; Sat, 30 May 2020 11:38:27 -0700 (PDT) Received: by mail-ej1-x641.google.com with SMTP id e2so5291890eje.13; Sat, 30 May 2020 11:38:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=message-id:subject:from:to:cc:date:in-reply-to:references :mime-version:content-transfer-encoding; bh=YwliNzdV3H/Ve6pKeZGydt7jOsfeEsBTpzoW3tVwaJQ=; b=lWOOuwFmWJQupZWqy0PetRo8YdXBhV8jNPiIY/7l5qI+mucX2wiFQJdPulL8YiKP9v XfO6a9yDrN2ne80QRS5YdGOEtjSTnybDJPjp1m5/urChuqPahnclEksjS/3MZDnyUPHu BoiyAm1eFkcOUr5tfKP72vMxtitaDtoZzQ/PE5r6WC3aa+EqHS2hr95jw/YoCq9wnqtL i5EETv5y4n0MQpCFbXaJiGnBbLCidR966goRRPC5jdfMctGjjO+Hhlf6sHVFgdkcRs8t vSrltKkLME7lfjWMW1x4JWayVgRGu77lhBUZ8Tt4y4aHK1VG7+sQ09+2bXwyIReheuiK 8y7A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:subject:from:to:cc:date:in-reply-to :references:mime-version:content-transfer-encoding; bh=YwliNzdV3H/Ve6pKeZGydt7jOsfeEsBTpzoW3tVwaJQ=; b=nvZHH2yK4NgQlGmtA8tKj5e0D+hgNX//VV00gmhau/8ePr3LiYUD99vEWerNjl+fYP wxfp+WaGJ79VpB97I/BzrF/Ef7l0/IEDq/Bf3weK0v/mYIhJEuE1GSzsj6qdmOSblV2E kK/LKLGVEumbR82AqBvviuNdJ5mcNz4oo3X79/WoLbocszE4yZ7FoVC/HbvzdQLNhXrc 4cyUNQfhN9S7VjQDCSJP6MFqOS63GSeC4xhqHTx79XGm3EYJ+ZeZvQv0V7zCvE3S7QhH AxMGBAv2w7anh5+sEjAT6kPSSunZvAT5fFLVtlwgw35i1MH2HHMY/SjkaZ9rk45SHo0O aTfg== X-Gm-Message-State: AOAM533jcE+xWVxJ9v5UWVvMFc80Js10TPNI26s9cR3vGVKNCfEhI8Xm BKyif/ceJK08ZG18bqc9zM8= X-Received: by 2002:a17:906:35cf:: with SMTP id p15mr12572312ejb.520.1590863906355; Sat, 30 May 2020 11:38:26 -0700 (PDT) Received: from ubuntu-laptop (ip5f5bfcfd.dynamic.kabel-deutschland.de. [95.91.252.253]) by smtp.googlemail.com with ESMTPSA id v13sm4570519eja.55.2020.05.30.11.38.25 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sat, 30 May 2020 11:38:25 -0700 (PDT) Message-ID: Subject: Re: [PATCH v4 3/4] scsi: ufs: cleanup ufs initialization path From: Bean Huo To: Avri Altman , "alim.akhtar@samsung.com" , "asutoshd@codeaurora.org" , "jejb@linux.ibm.com" , "martin.petersen@oracle.com" , "stanley.chu@mediatek.com" , "beanhuo@micron.com" , "bvanassche@acm.org" , "tomas.winkler@intel.com" , "cang@codeaurora.org" Cc: "linux-scsi@vger.kernel.org" , "linux-kernel@vger.kernel.org" Date: Sat, 30 May 2020 20:38:24 +0200 In-Reply-To: References: <20200529164054.27552-1-huobean@gmail.com> <20200529164054.27552-4-huobean@gmail.com> Content-Type: text/plain; charset="UTF-8" X-Mailer: Evolution 3.28.5-0ubuntu0.18.04.2 Mime-Version: 1.0 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Avri thanks your review. On Sat, 2020-05-30 at 06:37 +0000, Avri Altman wrote: > > - case QUERY_DESC_IDN_RFU_0: > > - case QUERY_DESC_IDN_RFU_1: > > You forgot to check that desc_id < QUERY_DESC_IDN_MAX I deleted it since I saw the caller has checked this. I will add back. > > > > + if (desc_id == QUERY_DESC_IDN_RFU_0 || desc_id == > > QUERY_DESC_IDN_RFU_1) > > *desc_len = 0; > > - break; > > - default: > > - *desc_len = 0; > > - return -EINVAL; > > - } > > - return 0; > > + else > > + *desc_len = hba->desc_size[desc_id]; > > } > > EXPORT_SYMBOL(ufshcd_map_desc_id_to_length); > > > > +static void ufshcd_update_desc_length(struct ufs_hba *hba, > > + enum desc_idn desc_id, > > + unsigned char desc_len) > > +{ > > + if (hba->desc_size[desc_id] == QUERY_DESC_MAX_SIZE && > > + desc_id != QUERY_DESC_IDN_STRING) > > + hba->desc_size[desc_id] = desc_len; > > +} > > + > > /** > > * ufshcd_read_desc_param - read the specified descriptor > > parameter > > * @hba: Pointer to adapter instance > > @@ -3168,16 +3105,11 @@ int ufshcd_read_desc_param(struct ufs_hba > > *hba, > > if (desc_id >= QUERY_DESC_IDN_MAX || !param_size) > > return -EINVAL; > > > > - /* Get the max length of descriptor from structure filled > > up at probe > > - * time. > > - */ > > - ret = ufshcd_map_desc_id_to_length(hba, desc_id, > > &buff_len); > > - > > - /* Sanity checks */ > > - if (ret || !buff_len) { > > - dev_err(hba->dev, "%s: Failed to get full > > descriptor length", > > - __func__); > > - return ret; > > + /* Get the length of descriptor */ > > + ufshcd_map_desc_id_to_length(hba, desc_id, &buff_len); > > + if (!buff_len) { > > + dev_err(hba->dev, "%s: Failed to get desc length", > > __func__); > > + return -EINVAL; > > } > > > > /* Check whether we need temp memory */ > > The first time we are reading the descriptor, we no longer can rely > on its true size. > So for this check, buff_len is 256 and kmalloc will always happen. > Do you think that this check is still relevant? you are right, I will delete this redundat code. > > /* Check whether we need temp memory */ > if (param_offset != 0 || param_size < buff_len) { > desc_buf = kmalloc(buff_len, GFP_KERNEL); > if (!desc_buf) > return -ENOMEM; > } else { > desc_buf = param_read_buf; > is_kmalloc = false; > } > > > > @@ -3209,6 +3141,9 @@ int ufshcd_read_desc_param(struct ufs_hba > > *hba, > > goto out; > > } > > > > + ufshcd_update_desc_length(hba, desc_id, > > + desc_buf[QUERY_DESC_LENGTH_OFFSET > > ]); > > + > > /* Check wherher we will not copy more data, than available > > */ > > if (is_kmalloc && param_size > buff_len) > > param_size = buff_len; > > And here, we might want to update buff_len to hold the true > descriptor size, > Before checking the copy-back buffer. > yes, buff_len should be updated here. will change it. thanks Bean