From patchwork Thu Oct 17 16:09:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jennifer Berringer X-Patchwork-Id: 836515 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (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 508CD1DE4CB for ; Thu, 17 Oct 2024 16:09:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729181371; cv=none; b=mX2O325qQE6bjU3JAEl0pdVqpeUB3wru5s4txFCN6K9wPqvUB4piMbUr1+msDer1BXwISpnBqfgZwIF/zE+wy2/FV5qNuP6cXZvsB9IKBPSGHqXd15dvCe6mdCOfw54+YCaWA1SzKETBPWSC2mJrW35JHpvq4ZJcj3skJkneX7o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729181371; c=relaxed/simple; bh=XWK2CQKBoDnkFJt4/MwIKSAF02nWN2yyjN0bWXOENEc=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=mRPwJ1e009rK6qwAqr4zHDICs35Sv9Dy7AIuVHCNWt1azNBn/ayJjvs42G2CWmbKWDbiu0nram+eMG7QNnc6Tg0gc8hsUoIYh/nZtFoisIAvWoNxEZ91DL6+zbWSOgxheb9Qj12mg6CP/GGRy8zZdOyylzKl81rqERqpc48rg+U= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=MRkt+j3e; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="MRkt+j3e" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1729181369; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=DkS5RbL+ncBye36HbvV2swXtYfvhlqwDI5lNtBAyr/g=; b=MRkt+j3etiA3uCxQHE7ZvUAxeLmr23xDwr79ke8bO+TAMGe0/29tEUu2ZR9AZEufnCh1K0 ycVNF6tbnEyik6htw3yvcjbmzSSNkj0KdklDiDooEwwaBd5tmKeWu6uY16vMhxUnN4Q33M uWMuKzWPVW4KaBTH71nxfXjGXdUOCXs= Received: from mail-ot1-f72.google.com (mail-ot1-f72.google.com [209.85.210.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-553-zj-J-moePWONCe-OcFKsgA-1; Thu, 17 Oct 2024 12:09:26 -0400 X-MC-Unique: zj-J-moePWONCe-OcFKsgA-1 Received: by mail-ot1-f72.google.com with SMTP id 46e09a7af769-718107b2091so906403a34.3 for ; Thu, 17 Oct 2024 09:09:26 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729181365; x=1729786165; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=DkS5RbL+ncBye36HbvV2swXtYfvhlqwDI5lNtBAyr/g=; b=tIa9hI7mdH/qhTyASmkUTMBq8iwDy3uVPah9HNWWrKFkW8rr2seBBM8kYXXBVnwQDZ al4QB0xpoxKLNSmsJUOZ0d/2dy6KFzhe2KiO9y2pLR6HVL9G5UAm5wFXAs74i7Rd91ba opbr27fkd37PRjxN61LnD3pKnELdK0SzI6flHv8rSpw8yqPgRKEtSwrDpKUk3bo9+Mgm RptwxchP5RtEzbnJLEWYroxbegfYDLTpMyS6iR7qJFh3VzBkFxDcyNgRKdnyNquFCuHF 3iTphL8NCiDn+L0RpMOkXdW6LgseOMOokT7bTl/Gd7wP/aplZjDXZii5WG9a0z1J4aBj ijvg== X-Forwarded-Encrypted: i=1; AJvYcCVkmwSsqAo8R24v7HaUyTV4Ug4AkEkKw4zdcAgd/bLgxypth/gRhHzkG6/X7vbvmAMUoEQmLvVMHQ==@vger.kernel.org X-Gm-Message-State: AOJu0Yx43IO4cPSZ7WeJef3rPjmgg6Yp4JykwVic0Q+5XstCFIuffxxj b9vetR05yrlnWigxwQGHRS9pBI5QupsKhtT2PI9YAEmLVL3Y55jgeKCRsjH84D7+IusVFtWNC+G d/f/e2gxX/AIu/XdB3nIXK934b4uEHaWobhD0/osXvPCPFg9NIiF4yEPg X-Received: by 2002:a05:6358:9490:b0:1c3:75c6:599a with SMTP id e5c5f4694b2df-1c3784bf6admr683541055d.21.1729181365635; Thu, 17 Oct 2024 09:09:25 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGfPycPZTZP+D3KLarN8Q1dwMVP6y29vgjcgbThfVJWEkcsbXkg/dm4qCNq6FkIFwCOC2vr1Q== X-Received: by 2002:a05:6358:9490:b0:1c3:75c6:599a with SMTP id e5c5f4694b2df-1c3784bf6admr683537955d.21.1729181365317; Thu, 17 Oct 2024 09:09:25 -0700 (PDT) Received: from localhost.localdomain (2603-9001-3d00-5353-0000-0000-0000-14c1.inf6.spectrum.com. [2603:9001:3d00:5353::14c1]) by smtp.gmail.com with ESMTPSA id 71dfb90a1353d-50d7b2a5a67sm881914e0c.42.2024.10.17.09.09.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Oct 2024 09:09:23 -0700 (PDT) From: Jennifer Berringer To: Srinivas Kandagatla , Sebastian Reichel , Greg Kroah-Hartman , Maxime Ripard Cc: linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, Jennifer Berringer Subject: [PATCH 1/3] nvmem: core: improve range check for nvmem_cell_write() Date: Thu, 17 Oct 2024 12:09:02 -0400 Message-ID: <20241017160904.2803663-1-jberring@redhat.com> X-Mailer: git-send-email 2.46.2 Precedence: bulk X-Mailing-List: linux-pm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 When __nvmem_cell_entry_write() is called for an nvmem cell that does not need bit shifting, it requires that the len parameter exactly matches the nvmem cell size. However, when the nvmem cell has a nonzero bit_offset, it was skipping this check. Accepting values of len larger than the cell size results in nvmem_cell_prepare_write_buffer() trying to write past the end of a heap buffer that it allocates. This patch adds a check to avoid that problem and instead return -EINVAL when len is too large. Rather than unconditionally checking that len exactly matches the nvmem cell size, allowing len to be smaller when bit shifts are involved may be helpful because some devices have nvmem cells that are less than 8 bits but span two bytes, although no current devices or drivers that do this seem to rely on nvmem_cell_write(). This possibility can be handled by nvmem_cell_prepare_write_buffer() because it allocates an appropriately-sized heap buffer and avoids reading past the end of buf. Fixes: 69aba7948cbe ("nvmem: Add a simple NVMEM framework for consumers") Signed-off-by: Jennifer Berringer --- drivers/nvmem/core.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) base-commit: 98f7e32f20d28ec452afb208f9cffc08448a2652 diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c index 33ffa2aa4c11..74bf4d35a7a7 100644 --- a/drivers/nvmem/core.c +++ b/drivers/nvmem/core.c @@ -1767,8 +1767,7 @@ static int __nvmem_cell_entry_write(struct nvmem_cell_entry *cell, void *buf, si struct nvmem_device *nvmem = cell->nvmem; int rc; - if (!nvmem || nvmem->read_only || - (cell->bit_offset == 0 && len != cell->bytes)) + if (!nvmem || nvmem->read_only) return -EINVAL; /* @@ -1780,9 +1779,13 @@ static int __nvmem_cell_entry_write(struct nvmem_cell_entry *cell, void *buf, si return -EINVAL; if (cell->bit_offset || cell->nbits) { + if (len > cell->bytes) + return -EINVAL; buf = nvmem_cell_prepare_write_buffer(cell, buf, len); if (IS_ERR(buf)) return PTR_ERR(buf); + } else if (len != cell->bytes) { + return -EINVAL; } rc = nvmem_reg_write(nvmem, cell->offset, buf, cell->bytes); From patchwork Thu Oct 17 16:09:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jennifer Berringer X-Patchwork-Id: 836990 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (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 4F33C1DD0D4 for ; Thu, 17 Oct 2024 16:09:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729181376; cv=none; b=c0Q3LY/erkM4SAckATNN1ikNZtP8ohl0eoC2359zWDfiMxL6zyCRoaAsUuGRvcleXhW+psxTyK3Kg4JEULaMhUXInMgwESHIH8CniNfP5PvVKrauTQPZcpsF/lgUF2dAF3C87Ihy+X5emb75QI4Wh7ttd1ExzMY/GoDMYirPTF4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729181376; c=relaxed/simple; bh=80JceXAUMBc0hDJiSFQQcdD4iRPY5w96kB8lL1EKvV0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=HQzFc0eUbEZ0WMdOlDkGzj76tPht0zkWjaHnBLgYadiDLUMhH2xhmefx+4gERZeQDqXWJl5Lr1tC8igZZd7jirzq8FOdbBBGrol1jgr8tNVmd4V6GX6JUivkSssTSL/kerUaVKahjphtjSMVts+kQco2A+dulwk2D+UxuSau1O4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=FZJ1z1a2; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="FZJ1z1a2" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1729181374; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=x3KIi5jhT8XRqt3YLNgG/2PEMhK9NfLcor1EN1FC7Zw=; b=FZJ1z1a2IuUwiGqmkn8GQoBaebgiYrF5v+uBA5vIpgArT/3GMmDI25f0JE32w//iMIvsKj P3UnSxeEVQB0lQlWQBzIWUsPRGD6WrtkytKDfbED8VzveMgrpWmNvHdUdqZHAxtqW1xhUL jL8mErqocGqobwBrD28+mXunPJ5SCXs= Received: from mail-vk1-f199.google.com (mail-vk1-f199.google.com [209.85.221.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-76-AF2mjVwSN5SWVRDVEiqjLQ-1; Thu, 17 Oct 2024 12:09:33 -0400 X-MC-Unique: AF2mjVwSN5SWVRDVEiqjLQ-1 Received: by mail-vk1-f199.google.com with SMTP id 71dfb90a1353d-50d374995b3so478988e0c.1 for ; Thu, 17 Oct 2024 09:09:33 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729181372; x=1729786172; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=x3KIi5jhT8XRqt3YLNgG/2PEMhK9NfLcor1EN1FC7Zw=; b=GU3hZub6kput10lillIbrDnzJW5MRcuIcIG5iqiXatq4Pr2O5jNCjDyy55cslKJ7fB UECXgEZ/WEhZl3SCYtj0nO+/35xThaqrgcglJk2E/9gvYXVQVbrMEhy2lwJy0WFYepKl /LR56qTnXExihaB+0Ld+xx3kz7V6M7fUEzahscW2i3j0jVEz1VUls3GA6TdVLujPKT+z t6TFYZAIvoG59hzvVdWoSZU0Q88tslz/mEu9YXbdd5YHdscaSEEsvL0Zbx2wzHXRjoVw GF9OUpMoZAyK6GpN+mGDK/HPSrkWFTGRMiuR7PB1101A+GolZtjuAqDgDc2j1lTlwlHV vL3Q== X-Forwarded-Encrypted: i=1; AJvYcCUqe/miUd2RDsSS27ZUycHPPq2cQf28V65Utq3f5VzevA9lQneRVKiLkTO5Dm6XrC9f1bOqStTQhA==@vger.kernel.org X-Gm-Message-State: AOJu0Yx1H9swyq9eE9ZIGN4Nq79/t7Is0diYmDyvg0FNQ+fcbNGoXI1L KyXiFChiuSxojE9MWnXLVrjpBc24M1U2DzOU85aILVIo33aR2Y23YknL+FlzuXsca2m4AvF8Wg5 U9oDRGiNVkOa+EBkZACi0Qtb4lUO4nkWFbQJSSJSLwYEKv5tPXWwJJQxx X-Received: by 2002:a05:6122:c98:b0:50a:49d1:f1f with SMTP id 71dfb90a1353d-50d1f5c24dfmr20606216e0c.13.1729181372331; Thu, 17 Oct 2024 09:09:32 -0700 (PDT) X-Google-Smtp-Source: AGHT+IER4G+Fz95k/I+hdY6XGfAQyo/Vj4u+zF8RuE5gYuvHARx4+3Zp7k7he+8cYNhe5n804JdQAQ== X-Received: by 2002:a05:6122:c98:b0:50a:49d1:f1f with SMTP id 71dfb90a1353d-50d1f5c24dfmr20606187e0c.13.1729181371993; Thu, 17 Oct 2024 09:09:31 -0700 (PDT) Received: from localhost.localdomain (2603-9001-3d00-5353-0000-0000-0000-14c1.inf6.spectrum.com. [2603:9001:3d00:5353::14c1]) by smtp.gmail.com with ESMTPSA id 71dfb90a1353d-50d7b2a5a67sm881914e0c.42.2024.10.17.09.09.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Oct 2024 09:09:31 -0700 (PDT) From: Jennifer Berringer To: Srinivas Kandagatla , Sebastian Reichel , Greg Kroah-Hartman , Maxime Ripard Cc: linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, Jennifer Berringer Subject: [PATCH 2/3] nvmem: core: add nvmem_cell_write_variable_u32() Date: Thu, 17 Oct 2024 12:09:03 -0400 Message-ID: <20241017160904.2803663-2-jberring@redhat.com> X-Mailer: git-send-email 2.46.2 In-Reply-To: <20241017160904.2803663-1-jberring@redhat.com> References: <20241017160904.2803663-1-jberring@redhat.com> Precedence: bulk X-Mailing-List: linux-pm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 This function allows nvmem consumers to write values of different sizes (1-4 bytes) to an nvmem cell without knowing the exact size, akin to a write counterpart to nvmem_cell_read_variable_le_32(). It discards the higher order bytes of the passed u32 value based on CPU endianness as necessary before writing to a cell smaller than 4 bytes. Signed-off-by: Jennifer Berringer --- drivers/nvmem/core.c | 24 ++++++++++++++++++++++++ include/linux/nvmem-consumer.h | 1 + 2 files changed, 25 insertions(+) diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c index 74bf4d35a7a7..6f7aa2beb457 100644 --- a/drivers/nvmem/core.c +++ b/drivers/nvmem/core.c @@ -1816,6 +1816,30 @@ int nvmem_cell_write(struct nvmem_cell *cell, void *buf, size_t len) EXPORT_SYMBOL_GPL(nvmem_cell_write); +/** + * nvmem_cell_write_variable_u32() - Write up to 32-bits of data as a host-endian number + * + * @cell: nvmem cell to be written. + * @val: Value to be written which may be truncated. + * + * Return: length of bytes written or negative on failure. + */ +int nvmem_cell_write_variable_u32(struct nvmem_cell *cell, u32 val) +{ + struct nvmem_cell_entry *entry = cell->entry; + u8 *buf = (u8 *) &val; + + if (!entry || entry->bytes > sizeof(u32)) + return -EINVAL; + +#ifdef __BIG_ENDIAN + buf += sizeof(u32) - entry->bytes; +#endif + + return __nvmem_cell_entry_write(entry, buf, entry->bytes); +} +EXPORT_SYMBOL_GPL(nvmem_cell_write_variable_u32); + static int nvmem_cell_read_common(struct device *dev, const char *cell_id, void *val, size_t count) { diff --git a/include/linux/nvmem-consumer.h b/include/linux/nvmem-consumer.h index 34c0e58dfa26..d3ede6916ecb 100644 --- a/include/linux/nvmem-consumer.h +++ b/include/linux/nvmem-consumer.h @@ -56,6 +56,7 @@ void nvmem_cell_put(struct nvmem_cell *cell); void devm_nvmem_cell_put(struct device *dev, struct nvmem_cell *cell); void *nvmem_cell_read(struct nvmem_cell *cell, size_t *len); int nvmem_cell_write(struct nvmem_cell *cell, void *buf, size_t len); +int nvmem_cell_write_variable_u32(struct nvmem_cell *cell, u32 val); int nvmem_cell_read_u8(struct device *dev, const char *cell_id, u8 *val); int nvmem_cell_read_u16(struct device *dev, const char *cell_id, u16 *val); int nvmem_cell_read_u32(struct device *dev, const char *cell_id, u32 *val); From patchwork Thu Oct 17 16:09:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jennifer Berringer X-Patchwork-Id: 836514 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (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 BA4721DF73C for ; Thu, 17 Oct 2024 16:09:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729181381; cv=none; b=mX+PZcqO0V8y/7zn7kJzFTorpR1WozsA9yj7zo+vxKWwPq2vVDGtxJGrKc0JmKJJroMqQAQkQkxyu/T/eamOjq9upxW8/CIf8FTunmoBOWsIqN2aYyoaa3ROcG1WcB0BEVv0lAHFO/xj3jtTVVlU+6rn6F/rQqIhkG/F0NPLQck= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729181381; c=relaxed/simple; bh=gLW0fh8PPs+BaOn5rkVzGVDEOg0uLVSjRbyJUCDLGBI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=RFfW0p1+sQ180ic/jsH4jBi6KWXJHeLD+W7A1thRmbmbd5gFfpBeY8Kcxu2HwG3BfmoUQduxKz/N8E0boRzSA1ihILbjeKI1foVel68GttFOYL34k+qkySCgvWbxtMShZ1aO1VJuGYdGkTiqEUXN0NpBzydNcwLDFdNacdb0OCo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=HmvhvKYw; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="HmvhvKYw" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1729181378; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=61B9Jq2TL9i1+pERa497eTJdtZBmCcAzgGgAjZWiZfs=; b=HmvhvKYwH7v1n5UEjU6Ef+frrk3JX+0By9YaiY0NMuCGkboUj5kQyAVEAucttVAJv5ovmr NxNjPK8ZVwrLgQcwGiW99scUGmFtrRMOJoOMy+zI+b6dmSqdNhBWryyx9acyZJstkVohZ5 4u/LTSyDbfC6RHt9xqRsowqOfbx9qHc= Received: from mail-vk1-f199.google.com (mail-vk1-f199.google.com [209.85.221.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-628-v-ZRMKvtPxywYQ3MyDvxog-1; Thu, 17 Oct 2024 12:09:37 -0400 X-MC-Unique: v-ZRMKvtPxywYQ3MyDvxog-1 Received: by mail-vk1-f199.google.com with SMTP id 71dfb90a1353d-50d32dc6574so390959e0c.3 for ; Thu, 17 Oct 2024 09:09:37 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729181377; x=1729786177; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=61B9Jq2TL9i1+pERa497eTJdtZBmCcAzgGgAjZWiZfs=; b=Bz+HYU7KUrtzEzxwv0o8iwrkvbkIK0jdhuen1aG0RAUDpzQ7ocVDsLvkOa9Ris+2HB gFSba9ypolZuMHdRjaac4DcX6y/fj928yxRT8RyI//OvWCxH/uq70lwFxBqzD4H4ExtJ 7l6WTaY219WSjDBjX1TlzxnliTFHxFVFQD3zT9eBC7NYUEl5+32xhDkOp05Bgg/Wb9bl 3Dl1E4S5oHaX/7JuuoyvGd34etV1xJqqhhS1H3eDE2PcNOwxKnDvdSxsSDifYdXXHmjR tOd1uv91yaYecqYDKCDM7T9FCuBTuZx/bcL8nqoh+XosyZLOAhoncGKej5/DIqljyWcr StqQ== X-Forwarded-Encrypted: i=1; AJvYcCVLUnJG4BUu8C8GBn/x9mt5ZmFHg60uhON8j0yeJzMJcVCVq36fLKcwEDs0KTwuKmMMlR/BpOOd1w==@vger.kernel.org X-Gm-Message-State: AOJu0YwF6uF9tfN0nUeihzm5Eh1Ad+9X+lxnXpNEB31hTWSwMlRFJWed N/ifDNZ0eu9AAjE0iO+m7nkLXmgSPLCyPDoTVR5va1PwC12bqGTgN7icLZtAdO7jemaC9gkZhDl Ra25OHwdB6yAvVtVhW5hXpJQ2yYUPwxmhitvZnrEl7LaFWnuvIwFiW6QV X-Received: by 2002:a05:6122:1da5:b0:50c:55f4:b529 with SMTP id 71dfb90a1353d-50d3771f4abmr12999435e0c.8.1729181377106; Thu, 17 Oct 2024 09:09:37 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF1E9vjWvTrSbjce44G1hNH9Te68qdHoX7qBSf5wcmDSozZzJlRu1XPR/BhkCpwGTTwrN+WLw== X-Received: by 2002:a05:6122:1da5:b0:50c:55f4:b529 with SMTP id 71dfb90a1353d-50d3771f4abmr12999408e0c.8.1729181376768; Thu, 17 Oct 2024 09:09:36 -0700 (PDT) Received: from localhost.localdomain (2603-9001-3d00-5353-0000-0000-0000-14c1.inf6.spectrum.com. [2603:9001:3d00:5353::14c1]) by smtp.gmail.com with ESMTPSA id 71dfb90a1353d-50d7b2a5a67sm881914e0c.42.2024.10.17.09.09.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Oct 2024 09:09:35 -0700 (PDT) From: Jennifer Berringer To: Srinivas Kandagatla , Sebastian Reichel , Greg Kroah-Hartman , Maxime Ripard Cc: linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, Jennifer Berringer Subject: [PATCH 3/3] power: reset: nvmem-reboot-mode: fix write for small cells Date: Thu, 17 Oct 2024 12:09:04 -0400 Message-ID: <20241017160904.2803663-3-jberring@redhat.com> X-Mailer: git-send-email 2.46.2 In-Reply-To: <20241017160904.2803663-1-jberring@redhat.com> References: <20241017160904.2803663-1-jberring@redhat.com> Precedence: bulk X-Mailing-List: linux-pm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Some devices, such as Qualcomm sa8775p, have an nvmem reboot mode cell that is smaller than 32 bits, which resulted in nvmem_reboot_mode_write() failing. Using nvmem_cell_write_variable_u32() fixes this by writing only the least-significant byte of the magic value when the size specified in device tree is only one byte. Signed-off-by: Jennifer Berringer --- drivers/power/reset/nvmem-reboot-mode.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/power/reset/nvmem-reboot-mode.c b/drivers/power/reset/nvmem-reboot-mode.c index 41530b70cfc4..b52eb879d1c1 100644 --- a/drivers/power/reset/nvmem-reboot-mode.c +++ b/drivers/power/reset/nvmem-reboot-mode.c @@ -24,7 +24,7 @@ static int nvmem_reboot_mode_write(struct reboot_mode_driver *reboot, nvmem_rbm = container_of(reboot, struct nvmem_reboot_mode, reboot); - ret = nvmem_cell_write(nvmem_rbm->cell, &magic, sizeof(magic)); + ret = nvmem_cell_write_variable_u32(nvmem_rbm->cell, magic); if (ret < 0) dev_err(reboot->dev, "update reboot mode bits failed\n");