mirror of
https://github.com/torvalds/linux.git
synced 2024-12-14 07:02:23 +00:00
23680f0b7d
The dev_uevent() in struct class should not be modifying the device that is passed into it, so mark it as a const * and propagate the function signature changes out into all relevant subsystems that use this callback. Cc: Jens Axboe <axboe@kernel.dk> Cc: Luis Chamberlain <mcgrof@kernel.org> Cc: Russ Weight <russell.h.weight@intel.com> Cc: Jean Delvare <jdelvare@suse.com> Cc: Johan Hovold <johan@kernel.org> Cc: Jason Gunthorpe <jgg@ziepe.ca> Cc: Leon Romanovsky <leon@kernel.org> Cc: Karsten Keil <isdn@linux-pingi.de> Cc: Mauro Carvalho Chehab <mchehab@kernel.org> Cc: Keith Busch <kbusch@kernel.org> Cc: Christoph Hellwig <hch@lst.de> Cc: Sagi Grimberg <sagi@grimberg.me> Cc: Dominik Brodowski <linux@dominikbrodowski.net> Cc: "David S. Miller" <davem@davemloft.net> Cc: Eric Dumazet <edumazet@google.com> Cc: Jakub Kicinski <kuba@kernel.org> Cc: Paolo Abeni <pabeni@redhat.com> Cc: Johannes Berg <johannes@sipsolutions.net> Cc: Wolfram Sang <wsa+renesas@sang-engineering.com> Cc: Raed Salem <raeds@nvidia.com> Cc: Chen Zhongjin <chenzhongjin@huawei.com> Cc: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp> Cc: Avihai Horon <avihaih@nvidia.com> Cc: "Matthew Wilcox (Oracle)" <willy@infradead.org> Cc: Alan Stern <stern@rowland.harvard.edu> Cc: Colin Ian King <colin.i.king@gmail.com> Cc: Geert Uytterhoeven <geert+renesas@glider.be> Cc: Jakob Koschel <jakobkoschel@gmail.com> Cc: Antoine Tenart <atenart@kernel.org> Cc: Frederic Weisbecker <frederic@kernel.org> Cc: Wang Yufen <wangyufen@huawei.com> Cc: linux-block@vger.kernel.org Cc: linux-kernel@vger.kernel.org Cc: linux-media@vger.kernel.org Cc: linux-nvme@lists.infradead.org Cc: linux-pm@vger.kernel.org Cc: linux-rdma@vger.kernel.org Cc: linux-usb@vger.kernel.org Cc: linux-wireless@vger.kernel.org Cc: netdev@vger.kernel.org Acked-by: Sebastian Reichel <sre@kernel.org> Acked-by: Rafael J. Wysocki <rafael@kernel.org> Link: https://lore.kernel.org/r/20221123122523.1332370-1-gregkh@linuxfoundation.org Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
186 lines
3.9 KiB
C
186 lines
3.9 KiB
C
// SPDX-License-Identifier: GPL-2.0
|
|
/* ATM driver model support. */
|
|
|
|
#include <linux/kernel.h>
|
|
#include <linux/slab.h>
|
|
#include <linux/init.h>
|
|
#include <linux/kobject.h>
|
|
#include <linux/atmdev.h>
|
|
#include "common.h"
|
|
#include "resources.h"
|
|
|
|
#define to_atm_dev(cldev) container_of(cldev, struct atm_dev, class_dev)
|
|
|
|
static ssize_t type_show(struct device *cdev,
|
|
struct device_attribute *attr, char *buf)
|
|
{
|
|
struct atm_dev *adev = to_atm_dev(cdev);
|
|
|
|
return scnprintf(buf, PAGE_SIZE, "%s\n", adev->type);
|
|
}
|
|
|
|
static ssize_t address_show(struct device *cdev,
|
|
struct device_attribute *attr, char *buf)
|
|
{
|
|
struct atm_dev *adev = to_atm_dev(cdev);
|
|
|
|
return scnprintf(buf, PAGE_SIZE, "%pM\n", adev->esi);
|
|
}
|
|
|
|
static ssize_t atmaddress_show(struct device *cdev,
|
|
struct device_attribute *attr, char *buf)
|
|
{
|
|
unsigned long flags;
|
|
struct atm_dev *adev = to_atm_dev(cdev);
|
|
struct atm_dev_addr *aaddr;
|
|
int count = 0;
|
|
|
|
spin_lock_irqsave(&adev->lock, flags);
|
|
list_for_each_entry(aaddr, &adev->local, entry) {
|
|
count += scnprintf(buf + count, PAGE_SIZE - count,
|
|
"%1phN.%2phN.%10phN.%6phN.%1phN\n",
|
|
&aaddr->addr.sas_addr.prv[0],
|
|
&aaddr->addr.sas_addr.prv[1],
|
|
&aaddr->addr.sas_addr.prv[3],
|
|
&aaddr->addr.sas_addr.prv[13],
|
|
&aaddr->addr.sas_addr.prv[19]);
|
|
}
|
|
spin_unlock_irqrestore(&adev->lock, flags);
|
|
|
|
return count;
|
|
}
|
|
|
|
static ssize_t atmindex_show(struct device *cdev,
|
|
struct device_attribute *attr, char *buf)
|
|
{
|
|
struct atm_dev *adev = to_atm_dev(cdev);
|
|
|
|
return scnprintf(buf, PAGE_SIZE, "%d\n", adev->number);
|
|
}
|
|
|
|
static ssize_t carrier_show(struct device *cdev,
|
|
struct device_attribute *attr, char *buf)
|
|
{
|
|
struct atm_dev *adev = to_atm_dev(cdev);
|
|
|
|
return scnprintf(buf, PAGE_SIZE, "%d\n",
|
|
adev->signal == ATM_PHY_SIG_LOST ? 0 : 1);
|
|
}
|
|
|
|
static ssize_t link_rate_show(struct device *cdev,
|
|
struct device_attribute *attr, char *buf)
|
|
{
|
|
struct atm_dev *adev = to_atm_dev(cdev);
|
|
int link_rate;
|
|
|
|
/* show the link rate, not the data rate */
|
|
switch (adev->link_rate) {
|
|
case ATM_OC3_PCR:
|
|
link_rate = 155520000;
|
|
break;
|
|
case ATM_OC12_PCR:
|
|
link_rate = 622080000;
|
|
break;
|
|
case ATM_25_PCR:
|
|
link_rate = 25600000;
|
|
break;
|
|
default:
|
|
link_rate = adev->link_rate * 8 * 53;
|
|
}
|
|
return scnprintf(buf, PAGE_SIZE, "%d\n", link_rate);
|
|
}
|
|
|
|
static DEVICE_ATTR_RO(address);
|
|
static DEVICE_ATTR_RO(atmaddress);
|
|
static DEVICE_ATTR_RO(atmindex);
|
|
static DEVICE_ATTR_RO(carrier);
|
|
static DEVICE_ATTR_RO(type);
|
|
static DEVICE_ATTR_RO(link_rate);
|
|
|
|
static struct device_attribute *atm_attrs[] = {
|
|
&dev_attr_atmaddress,
|
|
&dev_attr_address,
|
|
&dev_attr_atmindex,
|
|
&dev_attr_carrier,
|
|
&dev_attr_type,
|
|
&dev_attr_link_rate,
|
|
NULL
|
|
};
|
|
|
|
|
|
static int atm_uevent(const struct device *cdev, struct kobj_uevent_env *env)
|
|
{
|
|
const struct atm_dev *adev;
|
|
|
|
if (!cdev)
|
|
return -ENODEV;
|
|
|
|
adev = to_atm_dev(cdev);
|
|
if (!adev)
|
|
return -ENODEV;
|
|
|
|
if (add_uevent_var(env, "NAME=%s%d", adev->type, adev->number))
|
|
return -ENOMEM;
|
|
|
|
return 0;
|
|
}
|
|
|
|
static void atm_release(struct device *cdev)
|
|
{
|
|
struct atm_dev *adev = to_atm_dev(cdev);
|
|
|
|
kfree(adev);
|
|
}
|
|
|
|
static struct class atm_class = {
|
|
.name = "atm",
|
|
.dev_release = atm_release,
|
|
.dev_uevent = atm_uevent,
|
|
};
|
|
|
|
int atm_register_sysfs(struct atm_dev *adev, struct device *parent)
|
|
{
|
|
struct device *cdev = &adev->class_dev;
|
|
int i, j, err;
|
|
|
|
cdev->class = &atm_class;
|
|
cdev->parent = parent;
|
|
dev_set_drvdata(cdev, adev);
|
|
|
|
dev_set_name(cdev, "%s%d", adev->type, adev->number);
|
|
err = device_register(cdev);
|
|
if (err < 0)
|
|
return err;
|
|
|
|
for (i = 0; atm_attrs[i]; i++) {
|
|
err = device_create_file(cdev, atm_attrs[i]);
|
|
if (err)
|
|
goto err_out;
|
|
}
|
|
|
|
return 0;
|
|
|
|
err_out:
|
|
for (j = 0; j < i; j++)
|
|
device_remove_file(cdev, atm_attrs[j]);
|
|
device_del(cdev);
|
|
return err;
|
|
}
|
|
|
|
void atm_unregister_sysfs(struct atm_dev *adev)
|
|
{
|
|
struct device *cdev = &adev->class_dev;
|
|
|
|
device_del(cdev);
|
|
}
|
|
|
|
int __init atm_sysfs_init(void)
|
|
{
|
|
return class_register(&atm_class);
|
|
}
|
|
|
|
void __exit atm_sysfs_exit(void)
|
|
{
|
|
class_unregister(&atm_class);
|
|
}
|