From nobody Wed Dec 17 21:41:10 2025 Received: from todd.t-8ch.de (todd.t-8ch.de [159.69.126.157]) (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 88BD857CB6 for ; Sat, 21 Dec 2024 14:48:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=159.69.126.157 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734792495; cv=none; b=YOVOEmYocdS0/FJi19jYtLLlf3dZhH/rbEJQu/xx3l9M9PFKv/OsETDTCG8OpkVaUqBHO3lGFibYF+zbmTabi8Yu1GpxvETdLgDS2wBolzWl20JR+wyFTi8uZEAN0Lb7o6Zb+cYqaArLKDlpJVEepTnJ70vUt0/LStk3ek9Rebc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734792495; c=relaxed/simple; bh=H724roLIaoPip44zZqVVk4vtvisEZYzLS47/VZWgyws=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=W4LPIhb5Joq26gjTCWbz34wcC67tPOq0r08ONYrMo8WaVdpjsDp/corPEpEqMVsEa/jcXyY8GCsl6t8Yvd1Alh/el/N9I+DNcoIXX9G6zL2UAJgkzzEapxA4kDVFGEqwVcNhfbQ4MM844Btchb4fNNlt7JNW8SFX8CIInNLT/mM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=weissschuh.net; spf=pass smtp.mailfrom=weissschuh.net; dkim=pass (1024-bit key) header.d=weissschuh.net header.i=@weissschuh.net header.b=enMld3zO; arc=none smtp.client-ip=159.69.126.157 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=weissschuh.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=weissschuh.net Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=weissschuh.net header.i=@weissschuh.net header.b="enMld3zO" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=weissschuh.net; s=mail; t=1734792491; bh=H724roLIaoPip44zZqVVk4vtvisEZYzLS47/VZWgyws=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=enMld3zO6o9mSKLhYxKXQHG2Bbc+Rs+lByn+GiB88gzFWqhFsDLgpQ/CPRdpDkwKD RisG0Szjk9NMl3jV0HnhYxnY9RxEJQKbGKoKRg0Mm7dRmt8lVOdE/wwuwtbJH0YmkP Oe9bBtsCvEJPdBMgOEsOrZlpE0RK7Zxs2XA8QGsU= From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Date: Sat, 21 Dec 2024 15:48:10 +0100 Subject: [PATCH v2 4/9] misc: c2port: Calculate bin_attribute size through group callback Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241221-sysfs-const-bin_attr-misc-drivers-v2-4-ba5e79fe8771@weissschuh.net> References: <20241221-sysfs-const-bin_attr-misc-drivers-v2-0-ba5e79fe8771@weissschuh.net> In-Reply-To: <20241221-sysfs-const-bin_attr-misc-drivers-v2-0-ba5e79fe8771@weissschuh.net> To: Frederic Barrat , Andrew Donnellan , Arnd Bergmann , Greg Kroah-Hartman Cc: linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1734792490; l=1911; i=linux@weissschuh.net; s=20221212; h=from:subject:message-id; bh=H724roLIaoPip44zZqVVk4vtvisEZYzLS47/VZWgyws=; b=zsZ1GLJgkyJDB4FWW1KUeoShxFYHVmehKqs0aufi24x33PwPG/GMeCoROYkLYuZad1oVFmeqt CLu8iRDVOUhBfq6slRcQdzva8KpYTs09xWkYf0/7+lSRZ7Ffzo2Um7O X-Developer-Key: i=linux@weissschuh.net; a=ed25519; pk=KcycQgFPX2wGR5azS7RhpBqedglOZVgRPfdFSPB1LNw= Modifying the size of the global bin_attribute instance can be racy. Instead use the new .bin_size callback to do so safely. For this to work move the initialization of c2dev->ops before the call to device_create() as the size callback will need access to it. Signed-off-by: Thomas Wei=C3=9Fschuh --- drivers/misc/c2port/core.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/drivers/misc/c2port/core.c b/drivers/misc/c2port/core.c index 2bb1dd2511f9dd178b8c06baa460bb609f7f8fd7..f455d702b9cd4999648a57985e3= 05aac5301403f 100644 --- a/drivers/misc/c2port/core.c +++ b/drivers/misc/c2port/core.c @@ -874,9 +874,22 @@ static struct bin_attribute *c2port_bin_attrs[] =3D { NULL, }; =20 +static size_t c2port_bin_attr_size(struct kobject *kobj, + const struct bin_attribute *attr, + int i) +{ + struct c2port_device *c2dev =3D dev_get_drvdata(kobj_to_dev(kobj)); + + if (attr =3D=3D &bin_attr_flash_data) + return c2dev->ops->blocks_num * c2dev->ops->block_size; + + return attr->size; +} + static const struct attribute_group c2port_group =3D { .attrs =3D c2port_attrs, .bin_attrs =3D c2port_bin_attrs, + .bin_size =3D c2port_bin_attr_size, }; =20 static const struct attribute_group *c2port_groups[] =3D { @@ -912,8 +925,7 @@ struct c2port_device *c2port_device_register(char *name, if (ret < 0) goto error_idr_alloc; c2dev->id =3D ret; - - bin_attr_flash_data.size =3D ops->blocks_num * ops->block_size; + c2dev->ops =3D ops; =20 c2dev->dev =3D device_create(c2port_class, NULL, 0, c2dev, "c2port%d", c2dev->id); @@ -924,7 +936,6 @@ struct c2port_device *c2port_device_register(char *name, dev_set_drvdata(c2dev->dev, c2dev); =20 strscpy(c2dev->name, name, sizeof(c2dev->name)); - c2dev->ops =3D ops; mutex_init(&c2dev->mutex); =20 /* By default C2 port access is off */ --=20 2.47.1