Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp2318526pxu; Sat, 28 Nov 2020 10:00:51 -0800 (PST) X-Google-Smtp-Source: ABdhPJwIa5HAuO5tPlboEm0L9LoqoMkzTttF8VRAEJ9goFgN+YhlHKqrQ/Jd6oepXVlI/Nk70PTP X-Received: by 2002:a17:907:7253:: with SMTP id ds19mr14227764ejc.166.1606586451225; Sat, 28 Nov 2020 10:00:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1606586451; cv=none; d=google.com; s=arc-20160816; b=fmzcwV3qcT0s4HkzWpm7y/2XX3fUDLvTHPWdjCKGL7ioOEVQCx88i9XBvJjivu+A4m l68Jr9IOY4P9lEGpoPep5FDWjiCvGScFEQPUdpI40gLzPjSK55jq2usVx3W2mal5fqw7 fdUuIxCwu3nh5jTdASK2jSWjNaVAUhxXZlVIoF4B95Ki4Z1eHeRYcu//Q37fvSukw6qH 0LGoBoIcST5Ph2qRQ26Fuw1JFsOdp8hHhwvhKt68djVvoXhZ5kMEAdQXRJUt6cdTgMtL JIEskIj+eC1evix9HeSlaDf/aJsGRJ+qMfV3IKnAC4D/q4LNmStSeES/OnfH6zdLNhII vLUQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:date:cc:to:from:subject:message-id:dkim-signature :dkim-signature; bh=DtPdJGTA5nnMkc8P/pwQmVt219aLy5SeiarqR2H6jsk=; b=gUuBrkypuvbnP57aBSoTmo3BqkQAzp2q00Sx7l+WqJ+LMH0BdqKFD1gSQfYSl+vBbd ysa4O85/KTEDVCzcxvQ6ICPNzH98/+3ZvDjsytrMRIAqFoow8BnK0snFxlp+NQJPrrgx /3Qrsz0xb0Q2zolfBkh4p6EYx0McyaaXdrBS8J7cIV5D226K0bbhEiEeCeeLqDbDrq4t LGR//BATxYHemeu2RAX86Wd1hIjKWZ0e5OVByxEva+b7p4SO8O2YGs7OPQ1FS79UdVA7 7cUcVLhNbs+DK1tKcfV06DVPjlXt8glnqxtMVYHgB2fq0VkeQDqNRZRWZaObVhEZJ5yJ rF7A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@hansenpartnership.com header.s=20151216 header.b="vg3y/EoH"; dkim=pass header.i=@hansenpartnership.com header.s=20151216 header.b="vg3y/EoH"; 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=NONE dis=NONE) header.from=hansenpartnership.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id e26si2336503edr.162.2020.11.28.10.00.28; Sat, 28 Nov 2020 10:00:51 -0800 (PST) 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=@hansenpartnership.com header.s=20151216 header.b="vg3y/EoH"; dkim=pass header.i=@hansenpartnership.com header.s=20151216 header.b="vg3y/EoH"; 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=NONE dis=NONE) header.from=hansenpartnership.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732513AbgK0V5d (ORCPT + 99 others); Fri, 27 Nov 2020 16:57:33 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46518 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732290AbgK0V4e (ORCPT ); Fri, 27 Nov 2020 16:56:34 -0500 Received: from bedivere.hansenpartnership.com (bedivere.hansenpartnership.com [IPv6:2607:fcd0:100:8a00::2]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 69858C0613D1; Fri, 27 Nov 2020 13:56:34 -0800 (PST) Received: from localhost (localhost [127.0.0.1]) by bedivere.hansenpartnership.com (Postfix) with ESMTP id 3ABD812805D5; Fri, 27 Nov 2020 13:56:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=hansenpartnership.com; s=20151216; t=1606514192; bh=Ea+FO6Fv9PXJHIW1GiZoH8O6dvYG/m+z/pyBfg8cp4g=; h=Message-ID:Subject:From:To:Date:From; b=vg3y/EoHrnXmxuk3/695z5cvoNPCQEqicy9H5cuvk/s4/b4GSGamB2ayXNopFWUeV ziYnovXjSkixTFgqLoGHQHzF/WDiT9gN7xEIDq8V65jMr8vzw0ZceQantngt+pdpSJ cCtE4UNU92Pgan6LZ1asfkoDrNg7qBt7f0zcU+Ho= Received: from bedivere.hansenpartnership.com ([127.0.0.1]) by localhost (bedivere.hansenpartnership.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id RjZBCclJDqXV; Fri, 27 Nov 2020 13:56:32 -0800 (PST) Received: from jarvis.int.hansenpartnership.com (unknown [IPv6:2601:600:8280:66d1::527]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by bedivere.hansenpartnership.com (Postfix) with ESMTPSA id C99F212805CF; Fri, 27 Nov 2020 13:56:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=hansenpartnership.com; s=20151216; t=1606514192; bh=Ea+FO6Fv9PXJHIW1GiZoH8O6dvYG/m+z/pyBfg8cp4g=; h=Message-ID:Subject:From:To:Date:From; b=vg3y/EoHrnXmxuk3/695z5cvoNPCQEqicy9H5cuvk/s4/b4GSGamB2ayXNopFWUeV ziYnovXjSkixTFgqLoGHQHzF/WDiT9gN7xEIDq8V65jMr8vzw0ZceQantngt+pdpSJ cCtE4UNU92Pgan6LZ1asfkoDrNg7qBt7f0zcU+Ho= Message-ID: <4340233ae5e105c5617401f84a5ed13c341f5ecf.camel@HansenPartnership.com> Subject: [GIT PULL] SCSI fixes for 5.10-rc5 From: James Bottomley To: Andrew Morton , Linus Torvalds Cc: linux-scsi , linux-kernel Date: Fri, 27 Nov 2020 13:56:30 -0800 Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.34.4 MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Three small fixes in the UFS driver: two are for power management issues and the third is to fix a slew of problem in the sysfs code. The patch is available here: git://git.kernel.org/pub/scm/linux/kernel/git/jejb/scsi.git scsi-fixes The short changelog is: Can Guo (2): scsi: ufs: Make sure clk scaling happens only when HBA is runtime ACTIVE scsi: ufs: Fix unexpected values from ufshcd_read_desc_param() Stanley Chu (1): scsi: ufs: Fix race between shutdown and runtime resume flow And the diffstat: drivers/scsi/ufs/ufshcd.c | 37 +++++++++++++++++++++++-------------- 1 file changed, 23 insertions(+), 14 deletions(-) With full diff below. James --- diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c index 7a160b86adc6..0c148fcd24de 100644 --- a/drivers/scsi/ufs/ufshcd.c +++ b/drivers/scsi/ufs/ufshcd.c @@ -1294,8 +1294,15 @@ static int ufshcd_devfreq_target(struct device *dev, } spin_unlock_irqrestore(hba->host->host_lock, irq_flags); + pm_runtime_get_noresume(hba->dev); + if (!pm_runtime_active(hba->dev)) { + pm_runtime_put_noidle(hba->dev); + ret = -EAGAIN; + goto out; + } start = ktime_get(); ret = ufshcd_devfreq_scale(hba, scale_up); + pm_runtime_put(hba->dev); trace_ufshcd_profile_clk_scaling(dev_name(hba->dev), (scale_up ? "up" : "down"), @@ -3192,13 +3199,19 @@ int ufshcd_read_desc_param(struct ufs_hba *hba, /* 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__); + dev_err(hba->dev, "%s: Failed to get desc length\n", __func__); + return -EINVAL; + } + + if (param_offset >= buff_len) { + dev_err(hba->dev, "%s: Invalid offset 0x%x in descriptor IDN 0x%x, length 0x%x\n", + __func__, param_offset, desc_id, buff_len); return -EINVAL; } /* Check whether we need temp memory */ if (param_offset != 0 || param_size < buff_len) { - desc_buf = kmalloc(buff_len, GFP_KERNEL); + desc_buf = kzalloc(buff_len, GFP_KERNEL); if (!desc_buf) return -ENOMEM; } else { @@ -3212,14 +3225,14 @@ int ufshcd_read_desc_param(struct ufs_hba *hba, desc_buf, &buff_len); if (ret) { - dev_err(hba->dev, "%s: Failed reading descriptor. desc_id %d, desc_index %d, param_offset %d, ret %d", + dev_err(hba->dev, "%s: Failed reading descriptor. desc_id %d, desc_index %d, param_offset %d, ret %d\n", __func__, desc_id, desc_index, param_offset, ret); goto out; } /* Sanity check */ if (desc_buf[QUERY_DESC_DESC_TYPE_OFFSET] != desc_id) { - dev_err(hba->dev, "%s: invalid desc_id %d in descriptor header", + dev_err(hba->dev, "%s: invalid desc_id %d in descriptor header\n", __func__, desc_buf[QUERY_DESC_DESC_TYPE_OFFSET]); ret = -EINVAL; goto out; @@ -3229,12 +3242,12 @@ int ufshcd_read_desc_param(struct ufs_hba *hba, buff_len = desc_buf[QUERY_DESC_LENGTH_OFFSET]; ufshcd_update_desc_length(hba, desc_id, desc_index, buff_len); - /* Check wherher we will not copy more data, than available */ - if (is_kmalloc && (param_offset + param_size) > buff_len) - param_size = buff_len - param_offset; - - if (is_kmalloc) + if (is_kmalloc) { + /* Make sure we don't copy more data than available */ + if (param_offset + param_size > buff_len) + param_size = buff_len - param_offset; memcpy(param_read_buf, &desc_buf[param_offset], param_size); + } out: if (is_kmalloc) kfree(desc_buf); @@ -8900,11 +8913,7 @@ int ufshcd_shutdown(struct ufs_hba *hba) if (ufshcd_is_ufs_dev_poweroff(hba) && ufshcd_is_link_off(hba)) goto out; - if (pm_runtime_suspended(hba->dev)) { - ret = ufshcd_runtime_resume(hba); - if (ret) - goto out; - } + pm_runtime_get_sync(hba->dev); ret = ufshcd_suspend(hba, UFS_SHUTDOWN_PM); out: