From patchwork Mon Oct 24 11:30:47 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 8694 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp422594wru; Mon, 24 Oct 2022 05:23:01 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5nJR5ETdSAgCw/3QinL3IQSeQkWJBE4Cpz7zEde06lPLASAsUhYjvhK6m+LFxcZgUYnH+v X-Received: by 2002:aa7:dd45:0:b0:458:7474:1fbe with SMTP id o5-20020aa7dd45000000b0045874741fbemr30805787edw.334.1666614181475; Mon, 24 Oct 2022 05:23:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666614181; cv=none; d=google.com; s=arc-20160816; b=prg2oFHoyJ3Rohy3F8SeyAK98dNwy1S6qHRRJfEnRErCfOXoWEoDqWGU7ig+E8zZlu wdq7ZOhahSkebZoR2PizyCy+tVmNTY8b1lj7Ds5Q4Tng+y7bs66FMWHIhra0eQ5Vijzv AqxoToe6lRkWJmPJ4BgE6U72cSRlr3tFMyOtD4+Fwpf2mpdL+iOUOmiNdLaWxs2T9ox4 6b0Ydk6wzTTaoyRTdgH1pAQUWZJ5sZ9OdsEC6DWze04l23tV8Mn64/ce5cj5wKgACIGJ AxhdpThltBxOLgr13Fua6ebedMuWtBpTqd77Zbk+MA8LagQZPrjLnYlEhjIaTUaefEB9 XZqA== 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:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=itu0Tt8G+jkMMUauXlZ2Bt4qXBNHG5Ovltx6pgX4OUE=; b=EiumJdCC4yzEO4E1ChQgC25bWb+tdWqLVH4k72MAoGUGWFkwqyL2gs3DmTfgSnq/64 VtUW+WNSYfYWxVKx79R4WDr1S3GqBG6TjSzzO0cr8PNf526LPdTe7PXZa1H5tsbY086t uNDYUp4Wi99KyDCBKGA9fPqA/CJafS4kyPeSRne9vKUVUrUkRhzMSgKpBsJoz4RABfSI U4xx3yORqE9yl5RzbTJc+88XVBnG+xlqAQ0c5BFXEm34J0ysLnCExWv7aHEwcbikB7NR 68kaE+dQvt84f2UcknjEZjAVM6AyhNMwiHaxb9+IOErPKHDOU/jeZnAr5YaHtVuDoWVL UiMg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=gcMYBNzZ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id sh40-20020a1709076ea800b007413b206b16si27859658ejc.843.2022.10.24.05.22.36; Mon, 24 Oct 2022 05:23:01 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=gcMYBNzZ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233412AbiJXMVl (ORCPT + 99 others); Mon, 24 Oct 2022 08:21:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40706 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233495AbiJXMTk (ORCPT ); Mon, 24 Oct 2022 08:19:40 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D55167AB3D; Mon, 24 Oct 2022 04:58:10 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id B18886129A; Mon, 24 Oct 2022 11:51:03 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C5057C433C1; Mon, 24 Oct 2022 11:51:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666612263; bh=0hQmG0yLukZImX36wFn80tQrPCt+zD0IZ/UYg3RA9+Q=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=gcMYBNzZRLomqzmATpLhDN44XwFh8CocnT8Ub/iXflqY891xZcSCVPR5rR6KZOngc PttzhwjHl1Xmx3Rc+xE/3ph1PBvv7FDC7PCbh9LFK7kdT0tlM5ZV/UCGmx3DzVVpV1 DmwvlzaGXSuTf+z3X7ecx9Ov2HJrrXIqUaL66cYw= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Niklas Cassel , Damien Le Moal , Sasha Levin Subject: [PATCH 4.14 130/210] ata: fix ata_id_sense_reporting_enabled() and ata_id_has_sense_reporting() Date: Mon, 24 Oct 2022 13:30:47 +0200 Message-Id: <20221024113001.208606349@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221024112956.797777597@linuxfoundation.org> References: <20221024112956.797777597@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 X-Spam-Status: No, score=-7.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747571632288504056?= X-GMAIL-MSGID: =?utf-8?q?1747571632288504056?= From: Niklas Cassel [ Upstream commit 690aa8c3ae308bc696ec8b1b357b995193927083 ] ACS-5 section 7.13.6.41 Words 85..87, 120: Commands and feature sets supported or enabled states that: If bit 15 of word 86 is set to one, bit 14 of word 119 is set to one, and bit 15 of word 119 is cleared to zero, then word 119 is valid. If bit 15 of word 86 is set to one, bit 14 of word 120 is set to one, and bit 15 of word 120 is cleared to zero, then word 120 is valid. (This text also exists in really old ACS standards, e.g. ACS-3.) Currently, ata_id_sense_reporting_enabled() and ata_id_has_sense_reporting() both check bit 15 of word 86, but neither of them check that bit 14 of word 119 is set to one, or that bit 15 of word 119 is cleared to zero. Additionally, make ata_id_sense_reporting_enabled() return false if !ata_id_has_sense_reporting(), similar to how e.g. ata_id_flush_ext_enabled() returns false if !ata_id_has_flush_ext(). Fixes: e87fd28cf9a2 ("libata: Implement support for sense data reporting") Signed-off-by: Niklas Cassel Signed-off-by: Damien Le Moal Signed-off-by: Sasha Levin --- include/linux/ata.h | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/include/linux/ata.h b/include/linux/ata.h index c7a353825450..90a4c166c0fa 100644 --- a/include/linux/ata.h +++ b/include/linux/ata.h @@ -784,16 +784,21 @@ static inline bool ata_id_has_read_log_dma_ext(const u16 *id) static inline bool ata_id_has_sense_reporting(const u16 *id) { - if (!(id[ATA_ID_CFS_ENABLE_2] & (1 << 15))) + if (!(id[ATA_ID_CFS_ENABLE_2] & BIT(15))) + return false; + if ((id[ATA_ID_COMMAND_SET_3] & (BIT(15) | BIT(14))) != BIT(14)) return false; - return id[ATA_ID_COMMAND_SET_3] & (1 << 6); + return id[ATA_ID_COMMAND_SET_3] & BIT(6); } static inline bool ata_id_sense_reporting_enabled(const u16 *id) { - if (!(id[ATA_ID_CFS_ENABLE_2] & (1 << 15))) + if (!ata_id_has_sense_reporting(id)) + return false; + /* ata_id_has_sense_reporting() == true, word 86 must have bit 15 set */ + if ((id[ATA_ID_COMMAND_SET_4] & (BIT(15) | BIT(14))) != BIT(14)) return false; - return id[ATA_ID_COMMAND_SET_4] & (1 << 6); + return id[ATA_ID_COMMAND_SET_4] & BIT(6); } /**