From patchwork Mon Nov 4 15:23:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jennifer Berringer X-Patchwork-Id: 13861536 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 B9AAD1BDABE for ; Mon, 4 Nov 2024 15:24:26 +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=1730733868; cv=none; b=Viql2exzSmJwX6y2w1JifrkeNAJ4q7Y2NI5sKImWkBoBz/B5EmU0Zu/EwXAeuIJOsxI36nm4uEf9HPHT8DqJRwcfJjrKFlUH0aOKHVKTOP4/54wkKG5YwT51MmT7V6iRn6p1WgsARnMHP7ZKnjHYBDjCYT+qy3fCxbTNvsW1l/g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730733868; c=relaxed/simple; bh=3YbKA7i8Hg/FH1ulhSK2wdg0qEoMyhdpnPYUaZ5A+hA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=mxCgQ6axdEnLRo7Nfm7hu3NOW+4zIn3JROHA3e+xokfIzV1on5V//tGKwxnvEp5sb5hJTU4FE2W/o8eARQ3OFJX1hczY1iomf1a+5AhU++VlG9lyBpwU4Ns5suoSx1/nFPIKGDGLV5cMJyZ+I1MeD3xe17yB32vlVI2cqvekvp8= 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=VMRFl3tU; 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="VMRFl3tU" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1730733865; 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=WPAstAoRK19uFZHmiPTbsRc/dqP7WZfo+dg91IyOgb0=; b=VMRFl3tUped0xMFfDiiKFuhsL87reyiqe6DKY8ZRx+urXGpl0sgdd5xwxJjmBNQ33rM+WR /qnnQBNKB+O3KhGJ4CaotHVZo7Epm3hnF4qGVFO5aiWRV2GkpXZM9TMkppN0WsCG0aG43y 00OHUfATDvL4iDdFybbj/Nww1tYz3/k= Received: from mail-ot1-f71.google.com (mail-ot1-f71.google.com [209.85.210.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-614-6J1ls_L7M7CViUQgPnhKSw-1; Mon, 04 Nov 2024 10:24:24 -0500 X-MC-Unique: 6J1ls_L7M7CViUQgPnhKSw-1 Received: by mail-ot1-f71.google.com with SMTP id 46e09a7af769-71816436594so3519409a34.1 for ; Mon, 04 Nov 2024 07:24:24 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730733864; x=1731338664; 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=WPAstAoRK19uFZHmiPTbsRc/dqP7WZfo+dg91IyOgb0=; b=IZswiiE7vOMn9j7q1+XS/X2Oe33xD5YSxHL2qdyuGmWpdfGIuO5HFntTGvAJwUOqPh Y07g7sTrlHf4AY61F/5PrhVqYL3lJ/oIuRfWTC2GL/avOjXcd3VklVGo+rVsHD7FaAKj FIqPLT/pv3PkY3zH23K/5zvSl203qYQD80Rcu/4nKuRFYM9eMingn6xkX8CR/T86qxUU 2Sdr1//Smpk/doH22w7xuQUB2SRgetQEk0bYmfs7+4Wq1vEy1Y8GfbXj0EgQ/fyVtn6/ eQ2M8P8SoTipYqV0xhl/jKl/Kp2xDo3UE98/l4jVA/EMF2ZzxXa0tduW/ql6psrFzZ6k H1AA== X-Forwarded-Encrypted: i=1; AJvYcCWtkYv8uhK5NvlqMXBrMjRgCLLz5mpx+uOouEt7+1trgXOORkJh+igOf58B3jzD/1BNbtMirqOAUw==@vger.kernel.org X-Gm-Message-State: AOJu0YyJcDyPsbFwiOHhApVffg7RuZ4RyGB1fGbFQ/lzoC2y+VcgLEYa JhDGRSNXsFe2zN571yl/b8/CtdPW9rvmnl4jh3DDS735CRnOJC0D63zfSsa8Ksk6MULDG9Zigl+ TD0MPLj2FGe5XL1SxlYbQKKlrAXPU+jwc+Y/2LXoKm9QmG16FTMWp31f7 X-Received: by 2002:a05:6830:4486:b0:718:9ad9:3082 with SMTP id 46e09a7af769-7189d4a060cmr8138865a34.5.1730733863829; Mon, 04 Nov 2024 07:24:23 -0800 (PST) X-Google-Smtp-Source: AGHT+IEso+jw9fJAKQKBDcR1comcjsM6f+a0AKdQE2B08KoyHnQHHkZHbBPFR9MPYdc30JsDHmWDpA== X-Received: by 2002:a05:6830:4486:b0:718:9ad9:3082 with SMTP id 46e09a7af769-7189d4a060cmr8138836a34.5.1730733863477; Mon, 04 Nov 2024 07:24:23 -0800 (PST) Received: from rhdev.redhat.com (2603-9001-3d00-5353-0000-0000-0000-14c1.inf6.spectrum.com. [2603:9001:3d00:5353::14c1]) by smtp.gmail.com with ESMTPSA id 46e09a7af769-7189cc59b45sm1980847a34.6.2024.11.04.07.24.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Nov 2024 07:24:22 -0800 (PST) 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 v3 1/3] nvmem: core: improve range check for nvmem_cell_write() Date: Mon, 4 Nov 2024 10:23:10 -0500 Message-ID: <20241104152312.3813601-2-jberring@redhat.com> X-Mailer: git-send-email 2.46.2 In-Reply-To: <20241104152312.3813601-1-jberring@redhat.com> References: <20241104152312.3813601-1-jberring@redhat.com> 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. Add a check to avoid that problem and instead return -EINVAL when len doesn't match the number of bits expected by the nvmem cell when bit_offset is nonzero. This check uses cell->nbits in order to allow providing the smaller size to cells that are shifted into another byte by bit_offset. For example, a cell with nbits=8 and nonzero bit_offset would have bytes=2 but should accept a 1-byte write here, although no current callers depend on this. Fixes: 69aba7948cbe ("nvmem: Add a simple NVMEM framework for consumers") Signed-off-by: Jennifer Berringer --- drivers/nvmem/core.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c index 33ffa2aa4c11..4a5a6efe4bab 100644 --- a/drivers/nvmem/core.c +++ b/drivers/nvmem/core.c @@ -1780,6 +1780,8 @@ static int __nvmem_cell_entry_write(struct nvmem_cell_entry *cell, void *buf, si return -EINVAL; if (cell->bit_offset || cell->nbits) { + if (len != BITS_TO_BYTES(cell->nbits) && len != cell->bytes) + return -EINVAL; buf = nvmem_cell_prepare_write_buffer(cell, buf, len); if (IS_ERR(buf)) return PTR_ERR(buf); From patchwork Mon Nov 4 15:23:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jennifer Berringer X-Patchwork-Id: 13861537 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 580141C07E4 for ; Mon, 4 Nov 2024 15:24:28 +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=1730733869; cv=none; b=tNfGAP1C5raC/n7h5qrL6DSI6ltWM/+GAU/F1PhVjfOa88OamiI392H9/mL7YaDyTULkjzcRwTceJsOoEtWPHLBFjQtxeEij6EEfC026nqk5g4Tox/JbkX6kODd+KiUQPG26aa/bDmVJOCX1Yv4wgZ6TPn/UoNc4tT9G3dSlpOM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730733869; c=relaxed/simple; bh=aqqySA5j1pRC8DlotVBJm64W8spUlvU7b8sAN3b+Hw8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=tfo1c5QZvLCdtk+0HwsERZEKpqjK+GGJvAZ7T3jY8kJBILtOUva1Zt3/bcpwYK0yxFGq8UeNmK0EGazuLt6Cl8t1UuFpaFAOMVSOGXMjEqz3cDb8vhq+NJ3f1H5xF5GguPBnJF3ROlegNBZ5UjcNxvu57C5O2sOELe0m6C5V82c= 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=RdGNPRct; 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="RdGNPRct" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1730733867; 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=UPzGH1HlDZhak91zgf6eRebX7tyu+Q8KoBevHWuFYnk=; b=RdGNPRctrI/69BJCcHLOS0LuSQ0tUI53l6uBkN1t1og2Cl8YQlBhj44PEfLiXsU8GHg4T9 ppaVfUosBbJDscSQ2N7gnkE1Gp5IEEhPNAP+5ILmZ3fNidoTHeyuMr9kqB8Sofioz6/yC1 x2hAzDlF7OzxjrmFTIvYqld5i1vs9NA= Received: from mail-oa1-f69.google.com (mail-oa1-f69.google.com [209.85.160.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-453-mrQI6Q_CMYuA4EBd4Im3rw-1; Mon, 04 Nov 2024 10:24:26 -0500 X-MC-Unique: mrQI6Q_CMYuA4EBd4Im3rw-1 Received: by mail-oa1-f69.google.com with SMTP id 586e51a60fabf-28c6fee1d4eso3742888fac.1 for ; Mon, 04 Nov 2024 07:24:26 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730733865; x=1731338665; 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=UPzGH1HlDZhak91zgf6eRebX7tyu+Q8KoBevHWuFYnk=; b=cV613AoJe0LGC/LhPVBhCuFsDSgifv5wkXy8YcEbagG/P1CAGZEYIhNh0HyQlFHIJh +L7da05+Z7mHzxchp/gd6QGslfvVG2UDaazTHnIax2yKPmqat2pACxHCpDKmVEc5+8Wa pRArqt5I2J46UqVDAbTw03OaO9z54n3PpZFuoQRDk+hU0oxKBBxMOZmEhABZ1l5FGBxE dSkH7ZrC8nqf3JRzhAQSzjtWYrhns5KAYFS6TtIbDxxqjlSq6DjVfwLCHFiTl7g8SThJ cq/cYMVBbEDTw4Q1cx8gim1igMXz3CUPA7LAOdArbsrbDjofvqWRSXvb22HG7CNaJa94 oKbQ== X-Forwarded-Encrypted: i=1; AJvYcCXRPDivofFRY2JdnfAO3a4kato1vYhCr+UBjTB54K92GGgMw4wo43ND+wwFD85x0UjgSqvQFpmygQ==@vger.kernel.org X-Gm-Message-State: AOJu0YxlMpRjOvaH9kwRLaU9uWFkXmXEGpXveCOr4LLbcd6vsjBk6Ai5 iM0b65yR7hTs4T22r6EZbGyAemo+i+nR2OUY0V52htdVKwZgmpRGn6/qTmUdvpYczfmCx4hGt05 SREmRD7qXMa7x3/WRP0REsKKsMGexhfeyIT6xGUkqeJW9PfRSavpA51l4 X-Received: by 2002:a05:6870:7b4a:b0:270:1f1e:e3ea with SMTP id 586e51a60fabf-2948452db4cmr12813061fac.28.1730733865367; Mon, 04 Nov 2024 07:24:25 -0800 (PST) X-Google-Smtp-Source: AGHT+IFj98NljZQR88JEe0VSxR7EtOeVfTmAEjC0GbewfUtzio2cZ7PT81vFgnQCx8EL97YVmfE07A== X-Received: by 2002:a05:6870:7b4a:b0:270:1f1e:e3ea with SMTP id 586e51a60fabf-2948452db4cmr12813025fac.28.1730733864961; Mon, 04 Nov 2024 07:24:24 -0800 (PST) Received: from rhdev.redhat.com (2603-9001-3d00-5353-0000-0000-0000-14c1.inf6.spectrum.com. [2603:9001:3d00:5353::14c1]) by smtp.gmail.com with ESMTPSA id 46e09a7af769-7189cc59b45sm1980847a34.6.2024.11.04.07.24.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Nov 2024 07:24:24 -0800 (PST) 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 v3 2/3] nvmem: core: add nvmem_cell_write_variable_u32() Date: Mon, 4 Nov 2024 10:23:11 -0500 Message-ID: <20241104152312.3813601-3-jberring@redhat.com> X-Mailer: git-send-email 2.46.2 In-Reply-To: <20241104152312.3813601-1-jberring@redhat.com> References: <20241104152312.3813601-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 | 6 ++++++ 2 files changed, 30 insertions(+) diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c index 4a5a6efe4bab..4c26a5e8c361 100644 --- a/drivers/nvmem/core.c +++ b/drivers/nvmem/core.c @@ -1815,6 +1815,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..955366a07867 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); @@ -128,6 +129,11 @@ static inline int nvmem_cell_write(struct nvmem_cell *cell, return -EOPNOTSUPP; } +static inline int nvmem_cell_write_variable_u32(struct nvmem_cell *cell, u32 val) +{ + return -EOPNOTSUPP; +} + static inline int nvmem_cell_read_u8(struct device *dev, const char *cell_id, u8 *val) { From patchwork Mon Nov 4 15:23:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jennifer Berringer X-Patchwork-Id: 13861538 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 C40C41C07FB for ; Mon, 4 Nov 2024 15:24:29 +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=1730733871; cv=none; b=kljKSfH8lRkUwAd5GkoN8gkY1Aq8YFw+yt9CHHMXu+sDefhQu0H7nV9fParXXBHD5Jbt1erY6aZ7d7o6SHerjVZpWSE3X4VCU73rtxzY7T1JCVS/LlfXARgA7ATIx3aNf0jxTnt8wsctAe3Jf7pZF31aUOYnkTA0DINfbinnbbw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730733871; c=relaxed/simple; bh=gLW0fh8PPs+BaOn5rkVzGVDEOg0uLVSjRbyJUCDLGBI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=oQlAFv80FOEC8/fDp8Kb2kLsU/s4Jp4o4UKz/GGdXdixrTKw66WUTR41MT0cQ1OTvT3pFHboMXqPz0Uqa+WIDW3br/xNoS1U2p5oSsfUsu1uFazx07u3C4XQI2mFsmZ1P4JUZpKWfowd4WD7VtfxIFinw5kjdL6AL6SY0NkP/Uo= 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=GiJNeKvU; 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="GiJNeKvU" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1730733868; 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=GiJNeKvUi75jzFA+suZqnCqTcDEWhQOQ81TXplqqCMNvTl646pgt369ORIl8bLiFeceXGc cvPZ3e6qdPf9hhoRz2D7TMFHiLQxr0ObFyvF3ah1o/l76rcLmabkyVPS+eBb+7CX5ECedD gnh3itAiVl17JR1ykQOu9McdlUGE/7M= Received: from mail-oo1-f69.google.com (mail-oo1-f69.google.com [209.85.161.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-414-swv6YNAXOFOfTffsYX58Ow-1; Mon, 04 Nov 2024 10:24:27 -0500 X-MC-Unique: swv6YNAXOFOfTffsYX58Ow-1 Received: by mail-oo1-f69.google.com with SMTP id 006d021491bc7-5eb9c053637so3339891eaf.1 for ; Mon, 04 Nov 2024 07:24:27 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730733867; x=1731338667; 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=pZu7Rv6CUk6QP1xEa5vbG5gElxeYJNz2XMmllpLv4AZhx7Er4n8KZkIse3REP86Axf O9QFel43JGEforFIqBDg/zHGHKI8juAbbxpyJrF/kyaNIRIxPDSbOH7UYEHB8bnQQXs1 GpmrLe/F9N9uQv2Ep9A1OMyG59C6r0BA4hZnHafIzp4MFe3b3Dv5zzdWb5D71nfRaE4c 2nABFotlOO13jOKGPEjHZaMOL0CaWHX87JGHRyrH47WrM3iftOq/0sqJZ76iORPB68cs 747R3M03CPQ5tAzhEmczZU3glrVwoRj/1JjSkZH9A1ulnAyFklVIjk3MF3s4SjRnXejT 7ETg== X-Forwarded-Encrypted: i=1; AJvYcCXv4/pxIJodaynB1Gj6KJV6L271Zc3xPZy0Upkjz/cI5lQKaEhkav9d2W8zWZN9UxvY6iBBbcC4mQ==@vger.kernel.org X-Gm-Message-State: AOJu0Ywbg5Q8IcTqGcx6nRFvYzG1FIMiYYf0ssiMOx6ETAcKvryXGFPq Ivw0mNFCTWZl9Z8BYcKVPL2pXynw4YMhyXSOtIXqexgmm8paJtbGCQz0WGxJ56J4W8gnaqpwuF9 VsCj/uN0V9BjPgOkKru6wRRQXXHB5VWjTvr/TvSnN5B8AvCS6A/HYQhgW X-Received: by 2002:a05:6870:e0ca:b0:278:c6bf:fd34 with SMTP id 586e51a60fabf-29051bdaef8mr27449244fac.27.1730733866955; Mon, 04 Nov 2024 07:24:26 -0800 (PST) X-Google-Smtp-Source: AGHT+IGdz+LHCvEJnf6MEsvrtoajBkoyl90rdROWBh+jGnf8JMCALx0RuCy2tX6Sdh/r1DLTo3sGoQ== X-Received: by 2002:a05:6870:e0ca:b0:278:c6bf:fd34 with SMTP id 586e51a60fabf-29051bdaef8mr27449221fac.27.1730733866650; Mon, 04 Nov 2024 07:24:26 -0800 (PST) Received: from rhdev.redhat.com (2603-9001-3d00-5353-0000-0000-0000-14c1.inf6.spectrum.com. [2603:9001:3d00:5353::14c1]) by smtp.gmail.com with ESMTPSA id 46e09a7af769-7189cc59b45sm1980847a34.6.2024.11.04.07.24.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Nov 2024 07:24:25 -0800 (PST) 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 v3 3/3] power: reset: nvmem-reboot-mode: fix write for small cells Date: Mon, 4 Nov 2024 10:23:12 -0500 Message-ID: <20241104152312.3813601-4-jberring@redhat.com> X-Mailer: git-send-email 2.46.2 In-Reply-To: <20241104152312.3813601-1-jberring@redhat.com> References: <20241104152312.3813601-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 Reviewed-by: Sebastian Reichel --- 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");