5.10.163-rc1 review
Subsystems (11)
Greg Kroah-Hartman
maintainerPATCH 295/783 crypto: rockchip - rework by using crypto_engine
In reply to Greg Kroah-HartmanFrom: Corentin Labbe <[email protected]>
[ Upstream commit 57d67c6e8219b2a034c16d6149e30fb40fd39935 ]
Instead of doing manual queue management, let's use the crypto/engine for that.
In the same time, rework the requests handling to be easier to understand (and fix all bugs related to them).
--- drivers/crypto/Kconfig | 1 + drivers/crypto/rockchip/rk3288_crypto.c | 152 +---------- drivers/crypto/rockchip/rk3288_crypto.h | 39 +-- drivers/crypto/rockchip/rk3288_crypto_ahash.c | 144 +++++----- .../crypto/rockchip/rk3288_crypto_skcipher.c | 250 +++++++++--------- 5 files changed, 221 insertions(+), 365 deletions(-)
drivers/crypto/Kconfig +1 -0
@@ -754,6 +754,7 @@ config CRYPTO_DEV_ROCKCHIP select CRYPTO_CBC select CRYPTO_DES select CRYPTO_AES + select CRYPTO_ENGINE select CRYPTO_LIB_DES select CRYPTO_MD5 select CRYPTO_SHA1
drivers/crypto/rockchip/rk3288_crypto.c +9 -143
200 lines not on this page · raw message
drivers/crypto/rockchip/rk3288_crypto.h +10 -29
@@ -5,9 +5,11 @@#include <crypto/aes.h> #include <crypto/internal/des.h> #include <crypto/algapi.h> +#include <linux/dma-mapping.h> #include <linux/interrupt.h> #include <linux/delay.h> #include <linux/scatterlist.h> +#include <crypto/engine.h> #include <crypto/internal/hash.h> #include <crypto/internal/skcipher.h>
@@ -192,39 +194,15 @@ struct rk_crypto_info {struct reset_control *rst;void __iomem *reg;int irq; -struct crypto_queue queue; -struct tasklet_struct queue_task; -struct tasklet_struct done_task; -struct crypto_async_request *async_req; -int err; -/* device lock */ -spinlock_t lock; - -/* the public variable */ -struct scatterlist *sg_src; -struct scatterlist *sg_dst; -struct scatterlist *first; -unsigned int left_bytes; -size_t src_nents; -size_t dst_nents; -unsigned int total; -unsigned int count; -dma_addr_t addr_in; -dma_addr_t addr_out; -bool busy; -int (*start)(struct rk_crypto_info *dev); -int (*update)(struct rk_crypto_info *dev); -void (*complete)(struct crypto_async_request *base,int err); -int (*load_data)(struct rk_crypto_info *dev, -struct scatterlist *sg_src, -struct scatterlist *sg_dst); -void (*unload_data)(struct rk_crypto_info *dev); -int (*enqueue)(struct rk_crypto_info *dev, -struct crypto_async_request *async_req); + +struct crypto_engine *engine; +struct completion complete; +int status; };/* the private variable of hash */ struct rk_ahash_ctx { +struct crypto_engine_ctx enginectx;struct rk_crypto_info *dev;/* for fallback */ struct crypto_ahash *fallback_tfm;
@@ -234,10 +212,12 @@ struct rk_ahash_ctx {struct rk_ahash_rctx {struct ahash_request fallback_req;u32 mode; +int nrsg; };/* the private variable of cipher */ struct rk_cipher_ctx { +struct crypto_engine_ctx enginectx;struct rk_crypto_info *dev;unsigned int keylen;u8 key[AES_MAX_KEY_SIZE ];
@@ -246,6 +226,7 @@ struct rk_cipher_ctx { };struct rk_cipher_rctx { +u8 backup_iv[AES_BLOCK_SIZE ];u32 mode;struct skcipher_request fallback_req;// keep at the end };
drivers/crypto/rockchip/rk3288_crypto_ahash.c +78 -66
218 lines not on this page · raw message
drivers/crypto/rockchip/rk3288_crypto_skcipher.c +123 -127
328 lines not on this page · raw message
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 296/783 apparmor: Fix memleak in alloc_ns()
In reply to Greg Kroah-HartmanFrom: Xiu Jianfeng <[email protected]>
[ Upstream commit e9e6fa49dbab6d84c676666f3fe7d360497fd65b ]
After changes in commit a1bd627b46d1 ("apparmor: share profile name on replacement"), the hname member of struct aa_policy is not valid slab object, but a subset of that, it can not be freed by kfree_sensitive(), use aa_policy_destroy() to fix it.
--- security/apparmor/policy_ns.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
security/apparmor/policy_ns.c +1 -1
@@ -121,7 +121,7 @@ static struct aa_ns *alloc_ns(const char *prefix, const char *name)return ns; fail_unconfined: -kfree_sensitive (ns->base.hname); +aa_policy_destroy (&ns->base); fail_ns:kfree_sensitive (ns);return NULL ;
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 297/783 f2fs: fix normal discard process
In reply to Greg Kroah-HartmanFrom: Dongdong Zhang <[email protected]>
[ Upstream commit b5f1a218ae5e4339130d6e733f0e63d623e09a2c ]
In the DPOLICY_BG mode, there is a conflict between the two conditions "i + 1 < dpolicy->granularity" and "i < DEFAULT_DISCARD_GRANULARITY". If i = 15, the first condition is false, it will enter the second condition and dispatch all small granularity discards in function
__issue_discard_cmd_orderly. The restrictive effect
of the first condition to small discards will be invalidated. These two conditions should align.
--- fs/f2fs/segment.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/f2fs/segment.c +1 -1
@@ -1532,7 +1532,7 @@ static int __issue_discard_cmd(struct f2fs_sb_info *sbi,if (i +1 < dpolicy->granularity)break ; -if (i <DEFAULT_DISCARD_GRANULARITY && dpolicy->ordered) +if (i +1 <DEFAULT_DISCARD_GRANULARITY && dpolicy->ordered)return __issue_discard_cmd_orderly (sbi, dpolicy); pend_list = &dcc->pend_list[i];
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 298/783 RDMA/siw: Fix immediate work request flush to completion queue
In reply to Greg Kroah-HartmanFrom: Bernard Metzler <[email protected]>
[ Upstream commit bdf1da5df9da680589a7f74448dd0a94dd3e1446 ]
Correctly set send queue element opcode during immediate work request flushing in post sendqueue operation, if the QP is in ERROR state. An undefined ocode value results in out-of-bounds access to an array for mapping the opcode between siw internal and RDMA core representation in work completion generation. It resulted in a KASAN BUG report of type 'global-out-of-bounds' during NFSoRDMA testing.
This patch further fixes a potential case of a malicious user which may write undefined values for completion queue elements status or opcode, if the CQ is memory mapped to user land. It avoids the same out-of-bounds access to arrays for status and opcode mapping as described above.
--- drivers/infiniband/sw/siw/siw_cq.c | 24 ++++++++++++++-- drivers/infiniband/sw/siw/siw_verbs.c | 40 ++++++++++++++++++++++++--- 2 files changed, 58 insertions(+), 6 deletions(-)
drivers/infiniband/sw/siw/siw_cq.c +22 -2
@@ -56,8 +56,6 @@ int siw_reap_cqe(struct siw_cq *cq, struct ib_wc *wc)if (READ_ONCE (cqe->flags) &SIW_WQE_VALID ) {memset (wc,0 ,sizeof (*wc)); wc->wr_id = cqe->id; - wc->status = map_cqe_status[cqe->status].ib; - wc->opcode = map_wc_opcode[cqe->opcode]; wc->byte_len = cqe->bytes;/*
@@ -71,10 +69,32 @@ int siw_reap_cqe(struct siw_cq *cq, struct ib_wc *wc) wc->wc_flags =IB_WC_WITH_INVALIDATE ; } wc->qp = cqe->base_qp; + wc->opcode = map_wc_opcode[cqe->opcode]; + wc->status = map_cqe_status[cqe->status].ib;siw_dbg_cq (cq,"idx %u, type %d, flags %2x, id 0x%pK\n" , cq->cq_get % cq->num_cqe, cqe->opcode, cqe->flags, (void *)(uintptr_t )cqe->id); + }else { +/* +* A malicious user may set invalid opcode or +* status in the user mmapped CQE array. +* Sanity check and correct values in that case +* to avoid out-of-bounds access to global arrays +* for opcode and status mapping. +*/ +u8 opcode = cqe->opcode; +u16 status = cqe->status; + +if (opcode >=SIW_NUM_OPCODES ) { + opcode =0 ; + status =IB_WC_GENERAL_ERR ; + }else if (status >=SIW_NUM_WC_STATUS ) { + status =IB_WC_GENERAL_ERR ; + } + wc->opcode = map_wc_opcode[opcode]; + wc->status = map_cqe_status[status].ib; + }WRITE_ONCE (cqe->flags,0 ); cq->cq_get++;
drivers/infiniband/sw/siw/siw_verbs.c +36 -4
@@ -672,13 +672,45 @@ static int siw_copy_inline_sgl(const struct ib_send_wr *core_wr,static int siw_sq_flush_wr (struct siw_qp *qp,const struct ib_send_wr *wr,const struct ib_send_wr **bad_wr) { -struct siw_sqe sqe = {};int rv =0 ;while (wr) { - sqe.id = wr->wr_id; - sqe.opcode = wr->opcode; - rv =siw_sqe_complete (qp, &sqe,0 ,SIW_WC_WR_FLUSH_ERR ); +struct siw_sqe sqe = {}; + +switch (wr->opcode) { +case IB_WR_RDMA_WRITE : + sqe.opcode =SIW_OP_WRITE ; +break ; +case IB_WR_RDMA_READ : + sqe.opcode =SIW_OP_READ ; +break ; +case IB_WR_RDMA_READ_WITH_INV : + sqe.opcode =SIW_OP_READ_LOCAL_INV ; +break ; +case IB_WR_SEND : + sqe.opcode =SIW_OP_SEND ; +break ; +case IB_WR_SEND_WITH_IMM : + sqe.opcode =SIW_OP_SEND_WITH_IMM ; +break ; +case IB_WR_SEND_WITH_INV : + sqe.opcode =SIW_OP_SEND_REMOTE_INV ; +break ; +case IB_WR_LOCAL_INV : + sqe.opcode =SIW_OP_INVAL_STAG ; +break ; +case IB_WR_REG_MR : + sqe.opcode =SIW_OP_REG_MR ; +break ; +default : + rv = -EINVAL ; +break ; + } +if (!rv) { + sqe.id = wr->wr_id; + rv =siw_sqe_complete (qp, &sqe,0 , +SIW_WC_WR_FLUSH_ERR ); + }if (rv) {if (bad_wr) *bad_wr = wr;
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 299/783 RDMA/nldev: Return "-EAGAIN" if the cm_id isnt from expected port
In reply to Greg Kroah-HartmanFrom: Mark Zhang <[email protected]>
[ Upstream commit ecacb3751f254572af0009b9501e2cdc83a30b6a ]
When filling a cm_id entry, return "-EAGAIN" instead of 0 if the cm_id doesn'the have the same port as requested, otherwise an incomplete entry may be returned, which causes "rdam res show cm_id" to return an error.
For example on a machine with two rdma devices with "rping -C 1 -v -s" running background, the "rdma" command fails:
$ rdma -V rdma utility, iproute2-5.19.0 $ rdma res show cm_id link mlx5_0/- cm-idn 0 state LISTEN ps TCP pid 28056 comm rping src-addr 0.0.0.0:7174 error: Protocol not available
While with this fix it succeeds:
$ rdma res show cm_id link mlx5_0/- cm-idn 0 state LISTEN ps TCP pid 26395 comm rping src-addr 0.0.0.0:7174 link mlx5_1/- cm-idn 0 state LISTEN ps TCP pid 26395 comm rping src-addr 0.0.0.0:7174
--- drivers/infiniband/core/nldev.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/infiniband/core/nldev.c +1 -1
@@ -541,7 +541,7 @@ static int fill_res_cm_id_entry(struct sk_buff *msg, bool has_cap_net_admin,struct rdma_cm_id *cm_id = &id_priv->id;if (port && port != cm_id->port_num) -return 0 ; +return -EAGAIN ;if (cm_id->port_num &&nla_put_u32 (msg,RDMA_NLDEV_ATTR_PORT_INDEX , cm_id->port_num))
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 300/783 RDMA/siw: Set defined status for work completion with undefined status
In reply to Greg Kroah-HartmanFrom: Bernard Metzler <[email protected]>
[ Upstream commit 60da2d11fcbc043304910e4d2ca82f9bab953e63 ]
A malicious user may write undefined values into memory mapped completion queue elements status or opcode. Undefined status or opcode values will result in out-of-bounds access to an array mapping siw internal representation of opcode and status to RDMA core representation when reaping CQ elements. While siw detects those undefined values, it did not correctly set completion status to a defined value, thus defeating the whole purpose of the check.
This bug leads to the following Smatch static checker warning:
drivers/infiniband/sw/siw/siw_cq.c:96 siw_reap_cqe()
error: buffer overflow 'map_cqe_status' 10 <= 21
--- drivers/infiniband/sw/siw/siw_cq.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/infiniband/sw/siw/siw_cq.c +2 -2
@@ -88,9 +88,9 @@ int siw_reap_cqe(struct siw_cq *cq, struct ib_wc *wc)if (opcode >=SIW_NUM_OPCODES ) { opcode =0 ; - status =IB_WC_GENERAL_ERR ; + status =SIW_WC_GENERAL_ERR ; }else if (status >=SIW_NUM_WC_STATUS ) { - status =IB_WC_GENERAL_ERR ; + status =SIW_WC_GENERAL_ERR ; } wc->opcode = map_wc_opcode[opcode]; wc->status = map_cqe_status[status].ib;
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 301/783 scsi: scsi_debug: Fix a warning in resp_write_scat()
In reply to Greg Kroah-HartmanFrom: Harshit Mogalapalli <[email protected]>
[ Upstream commit 216e179724c1d9f57a8ababf8bd7aaabef67f01b ]
As 'lbdof_blen' is coming from user, if the size in kzalloc() is >= MAX_ORDER then we hit a warning.
Call trace:
sg_ioctl
sg_ioctl_common
scsi_ioctl
sg_scsi_ioctl
blk_execute_rq
blk_mq_sched_insert_request
blk_mq_run_hw_queue
__blk_mq_delay_run_hw_queue
__blk_mq_run_hw_queue
blk_mq_sched_dispatch_requests
__blk_mq_sched_dispatch_requests
blk_mq_dispatch_rq_list
scsi_queue_rq
scsi_dispatch_cmd
scsi_debug_queuecommand
schedule_resp
resp_write_scatIf you try to allocate a memory larger than(>=) MAX_ORDER, then kmalloc() will definitely fail. It creates a stack trace and messes up dmesg. The user controls the size here so if they specify a too large size it will fail.
Add __GFP_NOWARN in order to avoid too large allocation warning. This is detected by static analysis using smatch.
--- drivers/scsi/scsi_debug.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/scsi/scsi_debug.c +1 -1
@@ -3619,7 +3619,7 @@ static int resp_write_scat(struct scsi_cmnd *scp,mk_sense_buffer (scp,ILLEGAL_REQUEST ,INVALID_FIELD_IN_CDB ,0 );return illegal_condition_result; } - lrdp =kzalloc (lbdof_blen,GFP_ATOMIC ); + lrdp =kzalloc (lbdof_blen,GFP_ATOMIC | __GFP_NOWARN);if (lrdp ==NULL )return SCSI_MLQUEUE_HOST_BUSY ;if (sdebug_verbose)
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 302/783 crypto: ccree - Remove debugfs when platform_driver_register failed
In reply to Greg Kroah-HartmanFrom: Gaosheng Cui <[email protected]>
[ Upstream commit 4f1c596df706c9aca662b6c214fad84047ae2a97 ]
When platform_driver_register failed, we need to remove debugfs, which will caused a resource leak, fix it.
Failed logs as follows:
[ 32.606488] debugfs: Directory 'ccree' with parent '/' already present!
--- drivers/crypto/ccree/cc_driver.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)
drivers/crypto/ccree/cc_driver.c +9 -1
@@ -614,9 +614,17 @@ static struct platform_driver ccree_driver = {static int __init ccree_init (void ) { +int rc; +cc_debugfs_global_init (); -return platform_driver_register (&ccree_driver); + rc =platform_driver_register (&ccree_driver); +if (rc) { +cc_debugfs_global_fini (); +return rc; + } + +return 0 ; }module_init (ccree_init);
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 303/783 crypto: cryptd - Use request context instead of stack for sub-request
In reply to Greg Kroah-HartmanFrom: Herbert Xu <[email protected]>
[ Upstream commit 3a58c231172537f7b0e19d93ed33decd04f80eab ]
cryptd is buggy as it tries to use sync_skcipher without going through the proper sync_skcipher interface. In fact it doesn't even need sync_skcipher since it's already a proper skcipher and can easily access the request context instead of using something off the stack.
--- crypto/cryptd.c | 36 +++++++++++++++++++----------------- 1 file changed, 19 insertions(+), 17 deletions(-)
crypto/cryptd.c +19 -17
@@ -68,11 +68,12 @@ struct aead_instance_ctx {struct cryptd_skcipher_ctx {refcount_t refcnt; -struct crypto_sync_skcipher *child; +struct crypto_skcipher *child; };struct cryptd_skcipher_request_ctx {crypto_completion_t complete; +struct skcipher_request req; };struct cryptd_hash_ctx {
@@ -227,13 +228,13 @@ static int cryptd_skcipher_setkey(struct crypto_skcipher *parent, const u8 *key, unsigned int keylen) {struct cryptd_skcipher_ctx *ctx =crypto_skcipher_ctx (parent); -struct crypto_sync_skcipher *child = ctx->child; +struct crypto_skcipher *child = ctx->child; -crypto_sync_skcipher_clear_flags (child,CRYPTO_TFM_REQ_MASK ); -crypto_sync_skcipher_set_flags (child, -crypto_skcipher_get_flags (parent) & -CRYPTO_TFM_REQ_MASK ); -return crypto_sync_skcipher_setkey (child, key, keylen); +crypto_skcipher_clear_flags (child,CRYPTO_TFM_REQ_MASK ); +crypto_skcipher_set_flags (child, +crypto_skcipher_get_flags (parent) & +CRYPTO_TFM_REQ_MASK ); +return crypto_skcipher_setkey (child, key, keylen); }static void cryptd_skcipher_complete (struct skcipher_request *req,int err)
@@ -258,13 +259,13 @@ static void cryptd_skcipher_encrypt(struct crypto_async_request *base,struct cryptd_skcipher_request_ctx *rctx =skcipher_request_ctx (req);struct crypto_skcipher *tfm =crypto_skcipher_reqtfm (req);struct cryptd_skcipher_ctx *ctx =crypto_skcipher_ctx (tfm); -struct crypto_sync_skcipher *child = ctx->child; -SYNC_SKCIPHER_REQUEST_ON_STACK (subreq, child); +struct skcipher_request *subreq = &rctx->req; +struct crypto_skcipher *child = ctx->child;if (unlikely (err == -EINPROGRESS )) goto out; -skcipher_request_set_sync_tfm (subreq, child); +skcipher_request_set_tfm (subreq, child);skcipher_request_set_callback (subreq,CRYPTO_TFM_REQ_MAY_SLEEP ,NULL ,NULL ); skcipher_request_set_crypt(subreq, req->src, req->dst, req->cryptlen,
@@ -286,13 +287,13 @@ static void cryptd_skcipher_decrypt(struct crypto_async_request *base,struct cryptd_skcipher_request_ctx *rctx =skcipher_request_ctx (req);struct crypto_skcipher *tfm =crypto_skcipher_reqtfm (req);struct cryptd_skcipher_ctx *ctx =crypto_skcipher_ctx (tfm); -struct crypto_sync_skcipher *child = ctx->child; -SYNC_SKCIPHER_REQUEST_ON_STACK (subreq, child); +struct skcipher_request *subreq = &rctx->req; +struct crypto_skcipher *child = ctx->child;if (unlikely (err == -EINPROGRESS )) goto out; -skcipher_request_set_sync_tfm (subreq, child); +skcipher_request_set_tfm (subreq, child);skcipher_request_set_callback (subreq,CRYPTO_TFM_REQ_MAY_SLEEP ,NULL ,NULL ); skcipher_request_set_crypt(subreq, req->src, req->dst, req->cryptlen,
@@ -343,9 +344,10 @@ static int cryptd_skcipher_init_tfm(struct crypto_skcipher *tfm)if (IS_ERR (cipher))return PTR_ERR (cipher); - ctx->child = (struct crypto_sync_skcipher *)cipher; + ctx->child = cipher;crypto_skcipher_set_reqsize ( - tfm,sizeof (struct cryptd_skcipher_request_ctx )); + tfm,sizeof (struct cryptd_skcipher_request_ctx ) + +crypto_skcipher_reqsize (cipher));return 0 ; }
@@ -353,7 +355,7 @@ static void cryptd_skcipher_exit_tfm(struct crypto_skcipher *tfm) {struct cryptd_skcipher_ctx *ctx =crypto_skcipher_ctx (tfm); -crypto_free_sync_skcipher (ctx->child); +crypto_free_skcipher (ctx->child); }static void cryptd_skcipher_free (struct skcipher_instance *inst)
@@ -931,7 +933,7 @@ struct crypto_skcipher *cryptd_skcipher_child(struct cryptd_skcipher *tfm) {struct cryptd_skcipher_ctx *ctx =crypto_skcipher_ctx (&tfm->base); -return &ctx->child->base; +return ctx->child; }EXPORT_SYMBOL_GPL (cryptd_skcipher_child);
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 304/783 crypto: hisilicon/qm - add missing pci_dev_put() in q_num_set()
In reply to Greg Kroah-HartmanFrom: Xiongfeng Wang <[email protected]>
[ Upstream commit cc7710d0d4ebc6998f04035cde4f32c5ddbe9d7f ]
pci_get_device() will increase the reference count for the returned pci_dev. We need to use pci_dev_put() to decrease the reference count before q_num_set() returns.
--- drivers/crypto/hisilicon/qm.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/crypto/hisilicon/qm.h +4 -2
@@ -289,14 +289,14 @@ struct hisi_qp {static inline int q_num_set (const char *val,const struct kernel_param *kp,unsigned int device) { -struct pci_dev *pdev =pci_get_device (PCI_VENDOR_ID_HUAWEI , - device,NULL ); +struct pci_dev *pdev;u32 n, q_num;int ret;if (!val)return -EINVAL ; + pdev =pci_get_device (PCI_VENDOR_ID_HUAWEI , device,NULL );if (!pdev) { q_num =min_t (u32,QM_QNUM_V1 ,QM_QNUM_V2 ); pr_info("No device found currently, suppose queue number is %d\n",
@@ -306,6 +306,8 @@ static inline int q_num_set(const char *val, const struct kernel_param *kp, q_num =QM_QNUM_V1 ; else q_num =QM_QNUM_V2 ; + +pci_dev_put (pdev); } ret =kstrtou32 (val,10 , &n);
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 305/783 RDMA/hns: Repacing dseg_len by macros in fill_ext_sge_inl_data()
In reply to Greg Kroah-HartmanFrom: Luoyouming <[email protected]>
[ Upstream commit 3b1f864c904915b3baebffb31ea05ee704b0df3c ]
The sge size is known to be constant, so it's unnecessary to use sizeof to calculate.
Stable-dep-of: 8eaa6f7d569b ("RDMA/hns: Fix ext_sge num error when post send")
--- drivers/infiniband/hw/hns/hns_roce_hw_v2.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
drivers/infiniband/hw/hns/hns_roce_hw_v2.c +3 -4
@@ -159,8 +159,7 @@ static int fill_ext_sge_inl_data(struct hns_roce_qp *qp, unsigned int *sge_idx, u32 msg_len) {struct ib_device *ibdev = &(to_hr_dev (qp->ibqp.device))->ib_dev; -unsigned int dseg_len =sizeof (struct hns_roce_v2_wqe_data_seg ); -unsigned int ext_sge_sz = qp->sq.max_gs * dseg_len; +unsigned int ext_sge_sz = qp->sq.max_gs *HNS_ROCE_SGE_SIZE ;unsigned int left_len_in_pg;unsigned int idx = *sge_idx;unsigned int i =0 ;
@@ -188,7 +187,7 @@ static int fill_ext_sge_inl_data(struct hns_roce_qp *qp,if (len <= left_len_in_pg) {memcpy (dseg, addr, len); - idx += len / dseg_len; + idx += len /HNS_ROCE_SGE_SIZE ; i++;if (i >= wr->num_sge)
@@ -203,7 +202,7 @@ static int fill_ext_sge_inl_data(struct hns_roce_qp *qp, len -= left_len_in_pg; addr += left_len_in_pg; - idx += left_len_in_pg / dseg_len; + idx += left_len_in_pg /HNS_ROCE_SGE_SIZE ; dseg =hns_roce_get_extend_sge (qp, idx & (qp->sge.sge_cnt -1 )); left_len_in_pg =1 <<HNS_HW_PAGE_SHIFT ;
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 306/783 RDMA/hns: Fix ext_sge num error when post send
In reply to Greg Kroah-HartmanFrom: Luoyouming <[email protected]>
[ Upstream commit 8eaa6f7d569b4a22bfc1b0a3fdfeeb401feb65a4 ]
In the HNS ROCE driver, The sge is divided into standard sge and extended sge. There are 2 standard sge in RC/XRC, and the UD standard sge is 0. In the scenario of RC SQ inline, if the data does not exceed 32bytes, the standard sge will be used. If it exceeds, only the extended sge will be used to fill the data.
Currently, when filling the extended sge, max_gs is directly used as the number of the extended sge, which did not subtract the number of standard sge. There is a logical error. The new algorithm subtracts the number of standard sge from max_gs to get the actual number of extended sge.
--- drivers/infiniband/hw/hns/hns_roce_hw_v2.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-)
drivers/infiniband/hw/hns/hns_roce_hw_v2.c +11 -2
@@ -154,20 +154,29 @@ static void set_atomic_seg(const struct ib_send_wr *wr, V2_RC_SEND_WQE_BYTE_16_SGE_NUM_S, valid_num_sge); } +static unsigned int get_std_sge_num (struct hns_roce_qp *qp) +{ +if (qp->ibqp.qp_type ==IB_QPT_GSI || qp->ibqp.qp_type ==IB_QPT_UD ) +return 0 ; + +return HNS_ROCE_SGE_IN_WQE ; +} +static int fill_ext_sge_inl_data (struct hns_roce_qp *qp,const struct ib_send_wr *wr,unsigned int *sge_idx,u32 msg_len) {struct ib_device *ibdev = &(to_hr_dev (qp->ibqp.device))->ib_dev; -unsigned int ext_sge_sz = qp->sq.max_gs *HNS_ROCE_SGE_SIZE ;unsigned int left_len_in_pg;unsigned int idx = *sge_idx; +unsigned int std_sge_num;unsigned int i =0 ;unsigned int len;void *addr;void *dseg; -if (msg_len > ext_sge_sz) { + std_sge_num =get_std_sge_num (qp); +if (msg_len > (qp->sq.max_gs - std_sge_num) *HNS_ROCE_SGE_SIZE ) {ibdev_err (ibdev,"no enough extended sge space for inline data.\n" );return -EINVAL ;
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 307/783 PCI: Check for alloc failure in pci_request_irq()
In reply to Greg Kroah-HartmanFrom: Zeng Heng <[email protected]>
[ Upstream commit 2d9cd957d40c3ac491b358e7cff0515bb07a3a9c ]
When kvasprintf() fails to allocate memory, it returns a NULL pointer. Return error from pci_request_irq() so we don't dereference it.
--- drivers/pci/irq.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/pci/irq.c +2 -0
@@ -44,6 +44,8 @@ int pci_request_irq(struct pci_dev *dev, unsigned int nr, irq_handler_t handler,va_start (ap, fmt); devname =kvasprintf (GFP_KERNEL , fmt, ap);va_end (ap); +if (!devname) +return -ENOMEM ; ret =request_threaded_irq (pci_irq_vector (dev, nr), handler, thread_fn, irqflags, devname, dev_id);
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 308/783 RDMA/hfi: Decrease PCI device reference count in error path
In reply to Greg Kroah-HartmanFrom: Xiongfeng Wang <[email protected]>
[ Upstream commit 9b51d072da1d27e1193e84708201c48e385ad912 ]
pci_get_device() will increase the reference count for the returned pci_dev, and also decrease the reference count for the input parameter *from* if it is not NULL.
If we break out the loop in node_affinity_init() with 'dev' not NULL, we need to call pci_dev_put() to decrease the reference count. Add missing pci_dev_put() in error path.
--- drivers/infiniband/hw/hfi1/affinity.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/infiniband/hw/hfi1/affinity.c +2 -0
@@ -219,6 +219,8 @@ int node_affinity_init(void)for (node =0 ; node < node_affinity.num_possible_nodes; node++) hfi1_per_node_cntr[node] =1 ; +pci_dev_put (dev); +return 0 ; }
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 309/783 crypto: ccree - Make cc_debugfs_global_fini() available for module init function
In reply to Greg Kroah-HartmanFrom: Uwe Kleine-König <[email protected]>
[ Upstream commit 8e96729fc26c8967db45a3fb7a60387619f77a22 ]
ccree_init() calls cc_debugfs_global_fini(), the former is an init function and the latter an exit function though.
A modular build emits:
WARNING: modpost: drivers/crypto/ccree/ccree.o: section mismatch in reference: init_module (section: .init.text) -> cc_debugfs_global_fini (section: .exit.text)
(with CONFIG_DEBUG_SECTION_MISMATCH=y).
--- drivers/crypto/ccree/cc_debugfs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/crypto/ccree/cc_debugfs.c +1 -1
@@ -55,7 +55,7 @@ void __init cc_debugfs_global_init(void) cc_debugfs_dir =debugfs_create_dir ("ccree" ,NULL ); } -void __exit cc_debugfs_global_fini(void) +void cc_debugfs_global_fini (void ) {debugfs_remove (cc_debugfs_dir); }
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 310/783 RDMA/hns: fix memory leak in hns_roce_alloc_mr()
In reply to Greg Kroah-HartmanFrom: Zhengchao Shao <[email protected]>
[ Upstream commit a115aa00b18f7b8982b8f458149632caf64a862a ]
When hns_roce_mr_enable() failed in hns_roce_alloc_mr(), mr_key is not released. Compiled test only.
--- drivers/infiniband/hw/hns/hns_roce_mr.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/infiniband/hw/hns/hns_roce_mr.c +2 -2
@@ -456,10 +456,10 @@ struct ib_mr *hns_roce_alloc_mr(struct ib_pd *pd, enum ib_mr_type mr_type,return &mr->ibmr; -err_key: -free_mr_key (hr_dev, mr); err_pbl:free_mr_pbl (hr_dev, mr); +err_key: +free_mr_key (hr_dev, mr); err_free:kfree (mr);return ERR_PTR (ret);
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 311/783 RDMA/rxe: Fix NULL-ptr-deref in rxe_qp_do_cleanup() when socket create failed
In reply to Greg Kroah-HartmanFrom: Zhang Xiaoxu <[email protected]>
[ Upstream commit f67376d801499f4fa0838c18c1efcad8840e550d ]
There is a null-ptr-deref when mount.cifs over rdma:
BUG: KASAN: null-ptr-deref in rxe_qp_do_cleanup+0x2f3/0x360 [rdma_rxe] Read of size 8 at addr 0000000000000018 by task mount.cifs/3046 CPU: 2 PID: 3046 Comm: mount.cifs Not tainted 6.1.0-rc5+ #62 Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.14.0-1.fc3 Call Trace: <TASK> dump_stack_lvl+0x34/0x44 kasan_report+0xad/0x130 rxe_qp_do_cleanup+0x2f3/0x360 [rdma_rxe] execute_in_process_context+0x25/0x90 __rxe_cleanup+0x101/0x1d0 [rdma_rxe] rxe_create_qp+0x16a/0x180 [rdma_rxe] create_qp.part.0+0x27d/0x340 ib_create_qp_kernel+0x73/0x160 rdma_create_qp+0x100/0x230 _smbd_get_connection+0x752/0x20f0 smbd_get_connection+0x21/0x40 cifs_get_tcp_session+0x8ef/0xda0 mount_get_conns+0x60/0x750 cifs_mount+0x103/0xd00 cifs_smb3_do_mount+0x1dd/0xcb0 smb3_get_tree+0x1d5/0x300 vfs_get_tree+0x41/0xf0 path_mount+0x9b3/0xdd0 __x64_sys_mount+0x190/0x1d0 do_syscall_64+0x35/0x80 entry_SYSCALL_64_after_hwframe+0x46/0xb0
The root cause of the issue is the socket create failed in rxe_qp_init_req().
So move the reset rxe_qp_do_cleanup() after the NULL ptr check.
--- drivers/infiniband/sw/rxe/rxe_qp.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/infiniband/sw/rxe/rxe_qp.c +3 -3
@@ -812,12 +812,12 @@ static void rxe_qp_do_cleanup(struct work_struct *work) qp->resp.mr =NULL ; } -if (qp_type (qp) ==IB_QPT_RC ) -sk_dst_reset (qp->sk->sk); -free_rd_atomic_resources (qp);if (qp->sk) { +if (qp_type (qp) ==IB_QPT_RC ) +sk_dst_reset (qp->sk->sk); +kernel_sock_shutdown (qp->sk,SHUT_RDWR );sock_release (qp->sk); }
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 312/783 scsi: hpsa: Fix possible memory leak in hpsa_init_one()
In reply to Greg Kroah-HartmanFrom: Yuan Can <[email protected]>
[ Upstream commit 9c9ff300e0de07475796495d86f449340d454a0c ]
The hpda_alloc_ctlr_info() allocates h and its field reply_map. However, in hpsa_init_one(), if alloc_percpu() failed, the hpsa_init_one() jumps to clean1 directly, which frees h and leaks the h->reply_map.
Fix by calling hpda_free_ctlr_info() to release h->replay_map and h instead free h directly.
--- drivers/scsi/hpsa.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/scsi/hpsa.c +1 -1
@@ -8904,7 +8904,7 @@ static int hpsa_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)destroy_workqueue (h->monitor_ctlr_wq); h->monitor_ctlr_wq =NULL ; } -kfree (h); +hpda_free_ctlr_info (h);return rc; }
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 313/783 crypto: tcrypt - Fix multibuffer skcipher speed test mem leak
In reply to Greg Kroah-HartmanFrom: Zhang Yiqun <[email protected]>
[ Upstream commit 1aa33fc8d4032227253ceb736f47c52b859d9683 ]
In the past, the data for mb-skcipher test has been allocated twice, that means the first allcated memory area is without free, which may cause a potential memory leakage. So this patch is to remove one allocation to fix this error.
--- crypto/tcrypt.c | 9 --------- 1 file changed, 9 deletions(-)
crypto/tcrypt.c +0 -9
@@ -1282,15 +1282,6 @@ static void test_mb_skcipher_speed(const char *algo, int enc, int secs, goto out_free_tfm; } - -for (i =0 ; i < num_mb; ++i) -if (testmgr_alloc_buf (data[i].xbuf)) { -while (i--) -testmgr_free_buf (data[i].xbuf); - goto out_free_tfm; - } - -for (i =0 ; i < num_mb; ++i) { data[i].req =skcipher_request_alloc (tfm,GFP_KERNEL );if (!data[i].req) {
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 314/783 padata: Always leave BHs disabled when running ->parallel()
In reply to Greg Kroah-HartmanFrom: Daniel Jordan <[email protected]>
[ Upstream commit 34c3a47d20ae55b3600fed733bf96eafe9c500d5 ]
A deadlock can happen when an overloaded system runs ->parallel() in the context of the current task:
padata_do_parallel
->parallel()
pcrypt_aead_enc/dec
padata_do_serial
spin_lock(&reorder->lock) // BHs still enabled
<interrupt>
...
__do_softirq
...
padata_do_serial
spin_lock(&reorder->lock)It's a bug for BHs to be on in _do_serial as Steffen points out, so ensure they're off in the "current task" case like they are in padata_parallel_worker to avoid this situation.
--- kernel/padata.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)
kernel/padata.c +5 -3
@@ -220,14 +220,16 @@ int padata_do_parallel(struct padata_shell *ps, pw =padata_work_alloc ();spin_unlock (&padata_works_lock); +if (!pw) { +/* Maximum works limit exceeded, run in the current task. */ + padata->parallel (padata); + } +rcu_read_unlock_bh ();if (pw) {padata_work_init (pw, padata_parallel_worker, padata,0 );queue_work (pinst->parallel_wq, &pw->pw_work); - }else { -/* Maximum works limit exceeded, run in the current task. */ - padata->parallel (padata); }return 0 ;
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 315/783 padata: Fix list iterator in padata_do_serial()
In reply to Greg Kroah-HartmanFrom: Daniel Jordan <[email protected]>
[ Upstream commit 57ddfecc72a6c9941d159543e1c0c0a74fe9afdd ]
list_for_each_entry_reverse() assumes that the iterated list is nonempty and that every list_head is embedded in the same type, but its use in padata_do_serial() breaks both rules.
This doesn't cause any issues now because padata_priv and padata_list happen to have their list fields at the same offset, but we really shouldn't be relying on that.
--- kernel/padata.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
kernel/padata.c +5 -2
@@ -403,13 +403,16 @@ void padata_do_serial(struct padata_priv *padata)int hashed_cpu =padata_cpu_hash (pd, padata->seq_nr);struct padata_list *reorder =per_cpu_ptr (pd->reorder_list, hashed_cpu);struct padata_priv *cur; +struct list_head *pos;spin_lock (&reorder->lock);/* Sort in ascending order of sequence number. */ -list_for_each_entry_reverse (cur, &reorder->list, list) +list_for_each_prev (pos, &reorder->list) { + cur = list_entry(pos, struct padata_priv, list);if (cur->seq_nr < padata->seq_nr)break ; -list_add (&padata->list, &cur->list); + } +list_add (&padata->list, pos);spin_unlock (&reorder->lock);/*
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 316/783 scsi: mpt3sas: Fix possible resource leaks in mpt3sas_transport_port_add()
In reply to Greg Kroah-HartmanFrom: Yang Yingliang <[email protected]>
[ Upstream commit 78316e9dfc24906dd474630928ed1d3c562b568e ]
In mpt3sas_transport_port_add(), if sas_rphy_add() returns error, sas_rphy_free() needs be called to free the resource allocated in sas_end_device_alloc(). Otherwise a kernel crash will happen:
Unable to handle kernel NULL pointer dereference at virtual address 0000000000000108 CPU: 45 PID: 37020 Comm: bash Kdump: loaded Tainted: G W 6.1.0-rc1+ #189 pstate: 60000005 (nZCv daif -PAN -UAO -TCO -DIT -SSBS BTYPE=--) pc : device_del+0x54/0x3d0 lr : device_del+0x37c/0x3d0 Call trace: device_del+0x54/0x3d0 attribute_container_class_device_del+0x28/0x38 transport_remove_classdev+0x6c/0x80 attribute_container_device_trigger+0x108/0x110 transport_remove_device+0x28/0x38 sas_rphy_remove+0x50/0x78 [scsi_transport_sas] sas_port_delete+0x30/0x148 [scsi_transport_sas] do_sas_phy_delete+0x78/0x80 [scsi_transport_sas] device_for_each_child+0x68/0xb0 sas_remove_children+0x30/0x50 [scsi_transport_sas] sas_rphy_remove+0x38/0x78 [scsi_transport_sas] sas_port_delete+0x30/0x148 [scsi_transport_sas] do_sas_phy_delete+0x78/0x80 [scsi_transport_sas] device_for_each_child+0x68/0xb0 sas_remove_children+0x30/0x50 [scsi_transport_sas] sas_remove_host+0x20/0x38 [scsi_transport_sas] scsih_remove+0xd8/0x420 [mpt3sas]
Because transport_add_device() is not called when sas_rphy_add() fails, the device is not added. When sas_rphy_remove() is subsequently called to remove the device in the remove() path, a NULL pointer dereference happens.
--- drivers/scsi/mpt3sas/mpt3sas_transport.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/scsi/mpt3sas/mpt3sas_transport.c +2 -0
@@ -712,6 +712,8 @@ mpt3sas_transport_port_add(struct MPT3SAS_ADAPTER *ioc, u16 handle,if ((sas_rphy_add (rphy))) {ioc_err (ioc,"failure at %s:%d/%s()!\n" , __FILE__, __LINE__, __func__); +sas_rphy_free (rphy); + rphy =NULL ; }if (mpt3sas_port->remote_identify.device_type ==SAS_END_DEVICE ) {
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 317/783 scsi: hpsa: Fix error handling in hpsa_add_sas_host()
In reply to Greg Kroah-HartmanFrom: Yang Yingliang <[email protected]>
[ Upstream commit 4ef174a3ad9b5d73c1b6573e244ebba2b0d86eac ]
hpsa_sas_port_add_phy() does:
...
sas_phy_add() -> may return error here
sas_port_add_phy()
...
Whereas hpsa_free_sas_phy() does:
...
sas_port_delete_phy()
sas_phy_delete()
...
If hpsa_sas_port_add_phy() returns an error, hpsa_free_sas_phy() can not be called to free the memory because the port and the phy have not been added yet.
Replace hpsa_free_sas_phy() with sas_phy_free() and kfree() to avoid kernel crash in this case.
--- drivers/scsi/hpsa.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/scsi/hpsa.c +2 -1
@@ -9764,7 +9764,8 @@ static int hpsa_add_sas_host(struct ctlr_info *h)return 0 ; free_sas_phy: -hpsa_free_sas_phy (hpsa_sas_phy); +sas_phy_free (hpsa_sas_phy->phy); +kfree (hpsa_sas_phy); free_sas_port:hpsa_free_sas_port (hpsa_sas_port); free_sas_node:
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 318/783 scsi: hpsa: Fix possible memory leak in hpsa_add_sas_device()
In reply to Greg Kroah-HartmanFrom: Yang Yingliang <[email protected]>
[ Upstream commit fda34a5d304d0b98cc967e8763b52221b66dc202 ]
If hpsa_sas_port_add_rphy() returns an error, the 'rphy' allocated in sas_end_device_alloc() needs to be freed. Address this by calling sas_rphy_free() in the error path.
--- drivers/scsi/hpsa.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/scsi/hpsa.c +3 -1
@@ -9801,10 +9801,12 @@ static int hpsa_add_sas_device(struct hpsa_sas_node *hpsa_sas_node, rc =hpsa_sas_port_add_rphy (hpsa_sas_port, rphy);if (rc) - goto free_sas_port; + goto free_sas_rphy;return 0 ; +free_sas_rphy: +sas_rphy_free (rphy); free_sas_port:hpsa_free_sas_port (hpsa_sas_port); device->sas_port =NULL ;
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 319/783 scsi: scsi_debug: Fix a warning in resp_verify()
In reply to Greg Kroah-HartmanFrom: Harshit Mogalapalli <[email protected]>
[ Upstream commit ed0f17b748b20271cb568c7ca0b23b120316a47d ]
As 'vnum' is controlled by user, so if user tries to allocate memory larger than(>=) MAX_ORDER, then kcalloc() will fail, it creates a stack trace and messes up dmesg with a warning.
Add __GFP_NOWARN in order to avoid too large allocation warning. This is detected by static analysis using smatch.
--- drivers/scsi/scsi_debug.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/scsi/scsi_debug.c +1 -1
@@ -4275,7 +4275,7 @@ static int resp_verify(struct scsi_cmnd *scp, struct sdebug_dev_info *devip)if (ret)return ret; - arr =kcalloc (lb_size, vnum,GFP_ATOMIC ); + arr =kcalloc (lb_size, vnum,GFP_ATOMIC | __GFP_NOWARN);if (!arr) {mk_sense_buffer (scp,ILLEGAL_REQUEST ,INSUFF_RES_ASC ,INSUFF_RES_ASCQ );
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 320/783 scsi: scsi_debug: Fix a warning in resp_report_zones()
In reply to Greg Kroah-HartmanFrom: Harshit Mogalapalli <[email protected]>
[ Upstream commit 07f2ca139d9a7a1ba71c4c03997c8de161db2346 ]
As 'alloc_len' is user controlled data, if user tries to allocate memory larger than(>=) MAX_ORDER, then kcalloc() will fail, it creates a stack trace and messes up dmesg with a warning.
Add __GFP_NOWARN in order to avoid too large allocation warning. This is detected by static analysis using smatch.
--- drivers/scsi/scsi_debug.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/scsi/scsi_debug.c +1 -1
@@ -4346,7 +4346,7 @@ static int resp_report_zones(struct scsi_cmnd *scp, rep_max_zones =min ((alloc_len -64 ) >>ilog2 (RZONES_DESC_HD ), max_zones); - arr =kzalloc (alloc_len,GFP_ATOMIC ); + arr =kzalloc (alloc_len,GFP_ATOMIC | __GFP_NOWARN);if (!arr) {mk_sense_buffer (scp,ILLEGAL_REQUEST ,INSUFF_RES_ASC ,INSUFF_RES_ASCQ );
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 321/783 scsi: fcoe: Fix possible name leak when device_register() fails
In reply to Greg Kroah-HartmanFrom: Yang Yingliang <[email protected]>
[ Upstream commit 47b6a122c7b69a876c7ee2fc064a26b09627de9d ]
If device_register() returns an error, the name allocated by dev_set_name() needs to be freed. As the comment of device_register() says, one should use put_device() to give up the reference in the error path. Fix this by calling put_device(), then the name can be freed in kobject_cleanup().
The 'fcf' is freed in fcoe_fcf_device_release(), so the kfree() in the error path can be removed.
The 'ctlr' is freed in fcoe_ctlr_device_release(), so don't use the error label, just return NULL after calling put_device().
--- drivers/scsi/fcoe/fcoe_sysfs.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-)
drivers/scsi/fcoe/fcoe_sysfs.c +10 -9
@@ -830,14 +830,15 @@ struct fcoe_ctlr_device *fcoe_ctlr_device_add(struct device *parent,dev_set_name (&ctlr->dev,"ctlr_%d" , ctlr->id); error =device_register (&ctlr->dev); -if (error) - goto out_del_q2; +if (error) { +destroy_workqueue (ctlr->devloss_work_q); +destroy_workqueue (ctlr->work_q); +put_device (&ctlr->dev); +return NULL ; + }return ctlr; -out_del_q2: -destroy_workqueue (ctlr->devloss_work_q); - ctlr->devloss_work_q =NULL ; out_del_q:destroy_workqueue (ctlr->work_q); ctlr->work_q =NULL ;
@@ -1036,16 +1037,16 @@ struct fcoe_fcf_device *fcoe_fcf_device_add(struct fcoe_ctlr_device *ctlr, fcf->selected = new_fcf->selected; error =device_register (&fcf->dev); -if (error) - goto out_del; +if (error) { +put_device (&fcf->dev); + goto out; + } fcf->state =FCOE_FCF_STATE_CONNECTED ;list_add_tail (&fcf->peers, &ctlr->fcfs);return fcf; -out_del: -kfree (fcf); out:return NULL ; }
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 322/783 scsi: scsi_debug: Fix possible name leak in sdebug_add_host_helper()
In reply to Greg Kroah-HartmanFrom: Yang Yingliang <[email protected]>
[ Upstream commit e6d773f93a49e0eda88a903a2a6542ca83380eb1 ]
Afer commit 1fa5ae857bb1 ("driver core: get rid of struct device's bus_id string array"), the name of device is allocated dynamically, it needs be freed when device_register() returns error.
As comment of device_register() says, one should use put_device() to give up the reference in the error path. Fix this by calling put_device(), then the name can be freed in kobject_cleanup(), and sdbg_host is freed in sdebug_release_adapter().
When the device release is not set, it means the device is not initialized. We can not call put_device() in this case. Use kfree() to free memory.
--- drivers/scsi/scsi_debug.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/scsi/scsi_debug.c +4 -1
@@ -7103,7 +7103,10 @@ static int sdebug_add_host_helper(int per_host_idx)kfree (sdbg_devinfo->zstate);kfree (sdbg_devinfo); } -kfree (sdbg_host); +if (sdbg_host->dev.release) +put_device (&sdbg_host->dev); +else +kfree (sdbg_host);pr_warn ("%s: failed, errno=%d\n" , __func__, -error);return error; }
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 323/783 scsi: ipr: Fix WARNING in ipr_init()
In reply to Greg Kroah-HartmanFrom: Shang XiaoJing <[email protected]>
[ Upstream commit e6f108bffc3708ddcff72324f7d40dfcd0204894 ]
ipr_init() will not call unregister_reboot_notifier() when pci_register_driver() fails, which causes a WARNING. Call unregister_reboot_notifier() when pci_register_driver() fails.
notifier callback ipr_halt [ipr] already registered
WARNING: CPU: 3 PID: 299 at kernel/notifier.c:29 notifier_chain_register+0x16d/0x230 Modules linked in: ipr(+) xhci_pci_renesas xhci_hcd ehci_hcd usbcore led_class gpu_sched drm_buddy video wmi drm_ttm_helper ttm drm_display_helper drm_kms_helper drm drm_panel_orientation_quirks agpgart cfbft CPU: 3 PID: 299 Comm: modprobe Tainted: G W 6.1.0-rc1-00190-g39508d23b672-dirty #332 Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS rel-1.15.0-0-g2dd4b9b3f840-prebuilt.qemu.org 04/01/2014 RIP: 0010:notifier_chain_register+0x16d/0x230 Call Trace: <TASK> __blocking_notifier_chain_register+0x73/0xb0 ipr_init+0x30/0x1000 [ipr] do_one_initcall+0xdb/0x480 do_init_module+0x1cf/0x680 load_module+0x6a50/0x70a0 __do_sys_finit_module+0x12f/0x1c0 do_syscall_64+0x3f/0x90 entry_SYSCALL_64_after_hwframe+0x63/0xcd
--- drivers/scsi/ipr.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)
drivers/scsi/ipr.c +9 -1
@@ -10870,11 +10870,19 @@ static struct notifier_block ipr_notifier = {**/ static int __init ipr_init (void ) { +int rc; +ipr_info ("IBM Power RAID SCSI Device Driver version: %s %s\n" ,IPR_DRIVER_VERSION ,IPR_DRIVER_DATE );register_reboot_notifier (&ipr_notifier); -return pci_register_driver (&ipr_driver); + rc =pci_register_driver (&ipr_driver); +if (rc) { +unregister_reboot_notifier (&ipr_notifier); +return rc; + } + +return 0 ; }/**
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 324/783 scsi: fcoe: Fix transport not deattached when fcoe_if_init() fails
In reply to Greg Kroah-HartmanFrom: Chen Zhongjin <[email protected]>
[ Upstream commit 4155658cee394b22b24c6d64e49247bf26d95b92 ]
fcoe_init() calls fcoe_transport_attach(&fcoe_sw_transport), but when fcoe_if_init() fails, &fcoe_sw_transport is not detached and leaves freed &fcoe_sw_transport on fcoe_transports list. This causes panic when reinserting module.
BUG: unable to handle page fault for address: fffffbfff82e2213 RIP: 0010:fcoe_transport_attach+0xe1/0x230 [libfcoe] Call Trace: <TASK> do_one_initcall+0xd0/0x4e0 load_module+0x5eee/0x7210 ...
--- drivers/scsi/fcoe/fcoe.c | 1 + 1 file changed, 1 insertion(+)
drivers/scsi/fcoe/fcoe.c +1 -0
@@ -2504,6 +2504,7 @@ static int __init fcoe_init(void) out_free:mutex_unlock (&fcoe_config_mutex); +fcoe_transport_detach (&fcoe_sw_transport); out_destroy:destroy_workqueue (fcoe_wq);return rc;
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 325/783 scsi: snic: Fix possible UAF in snic_tgt_create()
In reply to Greg Kroah-HartmanFrom: Gaosheng Cui <[email protected]>
[ Upstream commit e118df492320176af94deec000ae034cc92be754 ]
Smatch reports a warning as follows:
drivers/scsi/snic/snic_disc.c:307 snic_tgt_create() warn:
'&tgt->list' not removed from list
If device_add() fails in snic_tgt_create(), tgt will be freed, but tgt->list will not be removed from snic->disc.tgt_list, then list traversal may cause UAF.
Remove from snic->disc.tgt_list before free().
--- drivers/scsi/snic/snic_disc.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/scsi/snic/snic_disc.c +3 -0
@@ -318,6 +318,9 @@ snic_tgt_create(struct snic *snic, struct snic_tgt_id *tgtid) ret);put_device (&snic->shost->shost_gendev); +spin_lock_irqsave (snic->shost->host_lock, flags); +list_del (&tgt->list); +spin_unlock_irqrestore (snic->shost->host_lock, flags);kfree (tgt); tgt =NULL ;
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 326/783 RDMA/nldev: Add checks for nla_nest_start() in fill_stat_counter_qps()
In reply to Greg Kroah-HartmanFrom: Yuan Can <[email protected]>
[ Upstream commit ea5ef136e215fdef35f14010bc51fcd6686e6922 ]
As the nla_nest_start() may fail with NULL returned, the return value needs to be checked.
--- drivers/infiniband/core/nldev.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/infiniband/core/nldev.c +2 -0
@@ -754,6 +754,8 @@ static int fill_stat_counter_qps(struct sk_buff *msg,int ret =0 ; table_attr =nla_nest_start (msg,RDMA_NLDEV_ATTR_RES_QP ); +if (!table_attr) +return -EMSGSIZE ; rt = &counter->device->res[RDMA_RESTRACK_QP ];xa_lock (&rt->xa);
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 327/783 f2fs: avoid victim selection from previous victim section
In reply to Greg Kroah-HartmanFrom: Yonggil Song <[email protected]>
[ Upstream commit e219aecfd4b766c4e878a3769057e9809f7fcadc ]
When f2fs chooses GC victim in large section & LFS mode, next_victim_seg[gc_type] is referenced first. After segment is freed, next_victim_seg[gc_type] has the next segment number.
However, next_victim_seg[gc_type] still has the last segment number even after the last segment of section is freed. In this case, when f2fs chooses a victim for the next GC round, the last segment of previous victim section is chosen as a victim.
Initialize next_victim_seg[gc_type] to NULL_SEGNO for the last segment in large section.
--- fs/f2fs/gc.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
fs/f2fs/gc.c +3 -2
@@ -1649,8 +1649,9 @@ static int do_garbage_collect(struct f2fs_sb_info *sbi, get_valid_blocks(sbi, segno, false) == 0) seg_freed++; -if (__is_large_section (sbi) && segno +1 < end_segno) - sbi->next_victim_seg[gc_type] = segno +1 ; +if (__is_large_section (sbi)) + sbi->next_victim_seg[gc_type] = + (segno +1 < end_segno) ? segno +1 :NULL_SEGNO ; skip:f2fs_put_page (sum_page,0 ); }
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 328/783 RDMA/nldev: Fix failure to send large messages
In reply to Greg Kroah-HartmanFrom: Mark Zhang <[email protected]>
[ Upstream commit fc8f93ad3e5485d45c992233c96acd902992dfc4 ]
Return "-EMSGSIZE" instead of "-EINVAL" when filling a QP entry, so that new SKBs will be allocated if there's not enough room in current SKB.
--- drivers/infiniband/core/nldev.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/infiniband/core/nldev.c +1 -1
@@ -502,7 +502,7 @@ static int fill_res_qp_entry(struct sk_buff *msg, bool has_cap_net_admin,/* In create_qp() port is not set yet */ if (qp->port &&nla_put_u32 (msg,RDMA_NLDEV_ATTR_PORT_INDEX , qp->port)) -return -EINVAL ; +return -EMSGSIZE ; ret =nla_put_u32 (msg,RDMA_NLDEV_ATTR_RES_LQPN , qp->qp_num);if (ret)
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 329/783 crypto: amlogic - Remove kcalloc without check
In reply to Greg Kroah-HartmanFrom: Christophe JAILLET <[email protected]>
[ Upstream commit 3d780c8a9850ad60dee47a8d971ba7888f3d1bd3 ]
There is no real point in allocating dedicated memory for the irqs array. MAXFLOW is only 2, so it is easier to allocated the needed space directly within the 'meson_dev' structure.
This saves some memory allocation and avoids an indirection when using the irqs array.
--- drivers/crypto/amlogic/amlogic-gxl-core.c | 1 - drivers/crypto/amlogic/amlogic-gxl.h | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-)
drivers/crypto/amlogic/amlogic-gxl-core.c +0 -1
@@ -240,7 +240,6 @@ static int meson_crypto_probe(struct platform_device *pdev)return err; } - mc->irqs =devm_kcalloc (mc->dev,MAXFLOW ,sizeof (int ),GFP_KERNEL );for (i =0 ; i <MAXFLOW ; i++) { mc->irqs[i] =platform_get_irq (pdev, i);if (mc->irqs[i] <0 )
drivers/crypto/amlogic/amlogic-gxl.h +1 -1
@@ -95,7 +95,7 @@ struct meson_dev {struct device *dev;struct meson_flow *chanlist;atomic_t flow; -int *irqs; +int irqs[MAXFLOW ];#ifdef CONFIG_CRYPTO_DEV_AMLOGIC_GXL_DEBUG struct dentry *dbgfs_dir;#endif
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 330/783 crypto: omap-sham - Use pm_runtime_resume_and_get() in omap_sham_probe()
In reply to Greg Kroah-HartmanFrom: Shang XiaoJing <[email protected]>
[ Upstream commit 7bcceb4c9896b1b672b636ae70fe75110d6bf1ad ]
omap_sham_probe() calls pm_runtime_get_sync() and calls pm_runtime_put_sync() latter to put usage_counter. However, pm_runtime_get_sync() will increment usage_counter even it failed. Fix it by replacing it with pm_runtime_resume_and_get() to keep usage counter balanced.
--- drivers/crypto/omap-sham.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/crypto/omap-sham.c +1 -1
@@ -2130,7 +2130,7 @@ static int omap_sham_probe(struct platform_device *pdev)pm_runtime_enable (dev);pm_runtime_irq_safe (dev); - err =pm_runtime_get_sync (dev); + err =pm_runtime_resume_and_get (dev);if (err <0 ) {dev_err (dev,"failed to get sync: %d\n" , err); goto err_pm;
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 331/783 riscv/mm: add arch hook arch_clear_hugepage_flags
In reply to Greg Kroah-HartmanFrom: Tong Tiangen <[email protected]>
[ Upstream commit d8bf77a1dc3079692f54be3087a5fd16d90027b0 ]
With the PG_arch_1 we keep track if the page's data cache is clean, architecture rely on this property to treat new pages as dirty with respect to the data cache and perform the flushing before mapping the pages into userspace.
This patch adds a new architecture hook, arch_clear_hugepage_flags,so that architectures which rely on the page flags being in a particular state for fresh allocations can adjust the flags accordingly when a page is freed into the pool.
--- arch/riscv/include/asm/hugetlb.h | 6 ++++++ 1 file changed, 6 insertions(+)
arch/riscv/include/asm/hugetlb.h +6 -0
@@ -5,4 +5,10 @@#include <asm-generic/hugetlb.h> #include <asm/page.h> +static inline void arch_clear_hugepage_flags (struct page *page) +{ +clear_bit (PG_dcache_clean, &page->flags); +} +#define arch_clear_hugepage_flags arch_clear_hugepage_flags +#endif /* _ASM_RISCV_HUGETLB_H */
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 332/783 RDMA/hfi1: Fix error return code in parse_platform_config()
In reply to Greg Kroah-HartmanFrom: Wang Yufen <[email protected]>
[ Upstream commit 725349f8ba1e78a146c6ff8f3ee5e2712e517106 ]
In the previous iteration of the while loop, the "ret" may have been assigned a value of 0, so the error return code -EINVAL may have been incorrectly set to 0. To fix set valid return code before calling to goto.
--- drivers/infiniband/hw/hfi1/firmware.c | 6 ++++++ 1 file changed, 6 insertions(+)
drivers/infiniband/hw/hfi1/firmware.c +6 -0
@@ -1786,6 +1786,7 @@ int parse_platform_config(struct hfi1_devdata *dd)if (!dd->platform_config.data) {dd_dev_err (dd,"%s: Missing config file\n" , __func__); + ret = -EINVAL ; goto bail; } ptr = (u32 *)dd->platform_config.data;
@@ -1794,6 +1795,7 @@ int parse_platform_config(struct hfi1_devdata *dd) ptr++;if (magic_num !=PLATFORM_CONFIG_MAGIC_NUM ) {dd_dev_err (dd,"%s: Bad config file\n" , __func__); + ret = -EINVAL ; goto bail; }
@@ -1817,6 +1819,7 @@ int parse_platform_config(struct hfi1_devdata *dd)if (file_length > dd->platform_config.size) {dd_dev_info (dd,"%s:File claims to be larger than read size\n" , __func__); + ret = -EINVAL ; goto bail; }else if (file_length < dd->platform_config.size) { dd_dev_info(dd,
@@ -1837,6 +1840,7 @@ int parse_platform_config(struct hfi1_devdata *dd)dd_dev_err (dd,"%s: Failed validation at offset %ld\n" , __func__, (ptr - (u32 *) dd->platform_config.data)); + ret = -EINVAL ; goto bail; }
@@ -1880,6 +1884,7 @@ int parse_platform_config(struct hfi1_devdata *dd) __func__, table_type, (ptr - (u32 *) dd->platform_config.data)); + ret = -EINVAL ; goto bail;/* We don't trust this file now */ } pcfgcache->config_tables[table_type].table = ptr;
@@ -1899,6 +1904,7 @@ int parse_platform_config(struct hfi1_devdata *dd) __func__, table_type, (ptr - (u32 *)dd->platform_config.data)); + ret = -EINVAL ; goto bail;/* We don't trust this file now */ } pcfgcache->config_tables[table_type].table_metadata =
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 333/783 RDMA/srp: Fix error return code in srp_parse_options()
In reply to Greg Kroah-HartmanFrom: Wang Yufen <[email protected]>
[ Upstream commit ed461b30b22c8fa85c25189c14cb89f29595cd14 ]
In the previous iteration of the while loop, the "ret" may have been assigned a value of 0, so the error return code -EINVAL may have been incorrectly set to 0. To fix set valid return code before calling to goto. Also investigate each case separately as Andy suggessted.
--- drivers/infiniband/ulp/srp/ib_srp.c | 96 ++++++++++++++++++++++++----- 1 file changed, 82 insertions(+), 14 deletions(-)
drivers/infiniband/ulp/srp/ib_srp.c +82 -14
@@ -3397,7 +3397,8 @@ static int srp_parse_options(struct net *net, const char *buf,break ;case SRP_OPT_PKEY : -if (match_hex (args, &token)) { + ret =match_hex (args, &token); +if (ret) {pr_warn ("bad P_Key parameter '%s'\n" , p); goto out; }
@@ -3457,7 +3458,8 @@ static int srp_parse_options(struct net *net, const char *buf,break ;case SRP_OPT_MAX_SECT : -if (match_int (args, &token)) { + ret =match_int (args, &token); +if (ret) {pr_warn ("bad max sect parameter '%s'\n" , p); goto out; }
@@ -3465,8 +3467,15 @@ static int srp_parse_options(struct net *net, const char *buf,break ;case SRP_OPT_QUEUE_SIZE : -if (match_int (args, &token) || token <1 ) { + ret =match_int (args, &token); +if (ret) { +pr_warn ("match_int() failed for queue_size parameter '%s', Error %d\n" , + p, ret); + goto out; + } +if (token <1 ) {pr_warn ("bad queue_size parameter '%s'\n" , p); + ret = -EINVAL ; goto out; } target->scsi_host->can_queue = token;
@@ -3477,25 +3486,40 @@ static int srp_parse_options(struct net *net, const char *buf,break ;case SRP_OPT_MAX_CMD_PER_LUN : -if (match_int (args, &token) || token <1 ) { + ret =match_int (args, &token); +if (ret) { +pr_warn ("match_int() failed for max cmd_per_lun parameter '%s', Error %d\n" , + p, ret); + goto out; + } +if (token <1 ) {pr_warn ("bad max cmd_per_lun parameter '%s'\n" , p); + ret = -EINVAL ; goto out; } target->scsi_host->cmd_per_lun = token;break ;case SRP_OPT_TARGET_CAN_QUEUE : -if (match_int (args, &token) || token <1 ) { + ret =match_int (args, &token); +if (ret) { +pr_warn ("match_int() failed for max target_can_queue parameter '%s', Error %d\n" , + p, ret); + goto out; + } +if (token <1 ) {pr_warn ("bad max target_can_queue parameter '%s'\n" , p); + ret = -EINVAL ; goto out; } target->target_can_queue = token;break ;case SRP_OPT_IO_CLASS : -if (match_hex (args, &token)) { + ret =match_hex (args, &token); +if (ret) {pr_warn ("bad IO class parameter '%s'\n" , p); goto out; }
@@ -3504,6 +3528,7 @@ static int srp_parse_options(struct net *net, const char *buf,pr_warn ("unknown IO class parameter value %x specified (use %x or %x).\n" , token,SRP_REV10_IB_IO_CLASS ,SRP_REV16A_IB_IO_CLASS ); + ret = -EINVAL ; goto out; } target->io_class = token;
@@ -3526,16 +3551,24 @@ static int srp_parse_options(struct net *net, const char *buf,break ;case SRP_OPT_CMD_SG_ENTRIES : -if (match_int (args, &token) || token <1 || token >255 ) { + ret =match_int (args, &token); +if (ret) { +pr_warn ("match_int() failed for max cmd_sg_entries parameter '%s', Error %d\n" , + p, ret); + goto out; + } +if (token <1 || token >255 ) {pr_warn ("bad max cmd_sg_entries parameter '%s'\n" , p); + ret = -EINVAL ; goto out; } target->cmd_sg_cnt = token;break ;case SRP_OPT_ALLOW_EXT_SG : -if (match_int (args, &token)) { + ret =match_int (args, &token); +if (ret) {pr_warn ("bad allow_ext_sg parameter '%s'\n" , p); goto out; }
@@ -3543,43 +3576,77 @@ static int srp_parse_options(struct net *net, const char *buf,break ;case SRP_OPT_SG_TABLESIZE : -if (match_int (args, &token) || token <1 || - token >SG_MAX_SEGMENTS ) { + ret =match_int (args, &token); +if (ret) { +pr_warn ("match_int() failed for max sg_tablesize parameter '%s', Error %d\n" , + p, ret); + goto out; + } +if (token <1 || token >SG_MAX_SEGMENTS ) {pr_warn ("bad max sg_tablesize parameter '%s'\n" , p); + ret = -EINVAL ; goto out; } target->sg_tablesize = token;break ;case SRP_OPT_COMP_VECTOR : -if (match_int (args, &token) || token <0 ) { + ret =match_int (args, &token); +if (ret) { +pr_warn ("match_int() failed for comp_vector parameter '%s', Error %d\n" , + p, ret); + goto out; + } +if (token <0 ) {pr_warn ("bad comp_vector parameter '%s'\n" , p); + ret = -EINVAL ; goto out; } target->comp_vector = token;break ;case SRP_OPT_TL_RETRY_COUNT : -if (match_int (args, &token) || token <2 || token >7 ) { + ret =match_int (args, &token); +if (ret) { +pr_warn ("match_int() failed for tl_retry_count parameter '%s', Error %d\n" , + p, ret); + goto out; + } +if (token <2 || token >7 ) {pr_warn ("bad tl_retry_count parameter '%s' (must be a number between 2 and 7)\n" , p); + ret = -EINVAL ; goto out; } target->tl_retry_count = token;break ;case SRP_OPT_MAX_IT_IU_SIZE : -if (match_int (args, &token) || token <0 ) { + ret =match_int (args, &token); +if (ret) { +pr_warn ("match_int() failed for max it_iu_size parameter '%s', Error %d\n" , + p, ret); + goto out; + } +if (token <0 ) {pr_warn ("bad maximum initiator to target IU size '%s'\n" , p); + ret = -EINVAL ; goto out; } target->max_it_iu_size = token;break ;case SRP_OPT_CH_COUNT : -if (match_int (args, &token) || token <1 ) { + ret =match_int (args, &token); +if (ret) { +pr_warn ("match_int() failed for channel count parameter '%s', Error %d\n" , + p, ret); + goto out; + } +if (token <1 ) {pr_warn ("bad channel count %s\n" , p); + ret = -EINVAL ; goto out; } target->ch_count = token;
@@ -3588,6 +3655,7 @@ static int srp_parse_options(struct net *net, const char *buf,default :pr_warn ("unknown parameter or missing value '%s' in target creation request\n" , p); + ret = -EINVAL ; goto out; } }
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 334/783 orangefs: Fix sysfs not cleanup when dev init failed
In reply to Greg Kroah-HartmanFrom: Zhang Xiaoxu <[email protected]>
[ Upstream commit ea60a4ad0cf88b411cde6888b8c890935686ecd7 ]
When the dev init failed, should cleanup the sysfs, otherwise, the module will never be loaded since can not create duplicate sysfs directory:
sysfs: cannot create duplicate filename '/fs/orangefs'
CPU: 1 PID: 6549 Comm: insmod Tainted: G W 6.0.0+ #44 Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.14.0-1.fc33 04/01/2014 Call Trace: <TASK> dump_stack_lvl+0x34/0x44 sysfs_warn_dup.cold+0x17/0x24 sysfs_create_dir_ns+0x16d/0x180 kobject_add_internal+0x156/0x3a0 kobject_init_and_add+0xcf/0x120 orangefs_sysfs_init+0x7e/0x3a0 [orangefs] orangefs_init+0xfe/0x1000 [orangefs] do_one_initcall+0x87/0x2a0 do_init_module+0xdf/0x320 load_module+0x2f98/0x3330 __do_sys_finit_module+0x113/0x1b0 do_syscall_64+0x35/0x80 entry_SYSCALL_64_after_hwframe+0x46/0xb0
kobject_add_internal failed for orangefs with -EEXIST, don't try to register things with the same name in the same directory.
--- fs/orangefs/orangefs-mod.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
fs/orangefs/orangefs-mod.c +4 -4
@@ -141,7 +141,7 @@ static int __init orangefs_init(void)gossip_err ("%s: could not initialize device subsystem %d!\n" , __func__, ret); - goto cleanup_device; + goto cleanup_sysfs; } ret =register_filesystem (&orangefs_fs_type);
@@ -152,11 +152,11 @@ static int __init orangefs_init(void) goto out; } -orangefs_sysfs_exit (); - -cleanup_device:orangefs_dev_cleanup (); +cleanup_sysfs: +orangefs_sysfs_exit (); + sysfs_init_failed:orangefs_debugfs_cleanup ();
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 335/783 RDMA/hns: Fix PBL page MTR find
In reply to Greg Kroah-HartmanFrom: Chengchang Tang <[email protected]>
[ Upstream commit 9fb39ef2ff3e18f1740625ba04093dfbef086d2b ]
Now, The address of the first two pages in the MR will be searched, which use to speed up the lookup of the pbl table for hardware. An exception will occur when there is only one page in this MR. This patch fix the number of page to search.
--- drivers/infiniband/hw/hns/hns_roce_hw_v2.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/infiniband/hw/hns/hns_roce_hw_v2.c +2 -1
@@ -2738,7 +2738,8 @@ static int set_mtpt_pbl(struct hns_roce_dev *hr_dev,int i, count; count =hns_roce_mtr_find (hr_dev, &mr->pbl_mtr,0 , pages, -ARRAY_SIZE (pages), &pbl_ba); +min_t (int,ARRAY_SIZE (pages), mr->npages), + &pbl_ba);if (count <1 ) {ibdev_err (ibdev,"failed to find PBL mtr, count = %d.\n" , count);
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 336/783 RDMA/hns: Fix page size cap from firmware
In reply to Greg Kroah-HartmanFrom: Chengchang Tang <[email protected]>
[ Upstream commit 99dc5a0712883d5d13b620d25b3759d429577bc8 ]
Add verification to make sure the roce page size cap is supported by the system page size.
--- drivers/infiniband/hw/hns/hns_roce_hw_v2.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/infiniband/hw/hns/hns_roce_hw_v2.c +3 -0
@@ -2166,6 +2166,9 @@ static int hns_roce_query_pf_caps(struct hns_roce_dev *hr_dev)calc_pg_sz (caps->num_idx_segs, caps->idx_entry_sz, caps->idx_hop_num,1 , &caps->idx_buf_pg_sz, &caps->idx_ba_pg_sz,HEM_TYPE_IDX ); +if (!(caps->page_size_cap &PAGE_SIZE )) + caps->page_size_cap =HNS_ROCE_V2_PAGE_SIZE_SUPPORTED ; +return 0 ; }
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 337/783 crypto: img-hash - Fix variable dereferenced before check hdev->req
In reply to Greg Kroah-HartmanFrom: Gaosheng Cui <[email protected]>
[ Upstream commit 04ba54e5af8f8f0137b08cb51a0b3a2e1ea46c94 ]
Smatch report warning as follows:
drivers/crypto/img-hash.c:366 img_hash_dma_task() warn: variable dereferenced before check 'hdev->req'
Variable dereferenced should be done after check 'hdev->req', fix it.
--- drivers/crypto/img-hash.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/crypto/img-hash.c +6 -2
@@ -357,12 +357,16 @@ static int img_hash_dma_init(struct img_hash_dev *hdev)static void img_hash_dma_task (unsigned long d) {struct img_hash_dev *hdev = (struct img_hash_dev *)d; -struct img_hash_request_ctx *ctx =ahash_request_ctx (hdev->req); +struct img_hash_request_ctx *ctx;u8 *addr;size_t nbytes, bleft, wsend, len, tbc;struct scatterlist tsg; -if (!hdev->req || !ctx->sg) +if (!hdev->req) +return ; + + ctx =ahash_request_ctx (hdev->req); +if (!ctx->sg)return ; addr =sg_virt (ctx->sg);
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 338/783 hwrng: amd - Fix PCI device refcount leak
In reply to Greg Kroah-HartmanFrom: Xiongfeng Wang <[email protected]>
[ Upstream commit ecadb5b0111ea19fc7c240bb25d424a94471eb7d ]
for_each_pci_dev() is implemented by pci_get_device(). The comment of pci_get_device() says that it will increase the reference count for the returned pci_dev and also decrease the reference count for the input pci_dev @from if it is not NULL.
If we break for_each_pci_dev() loop with pdev not NULL, we need to call pci_dev_put() to decrease the reference count. Add the missing pci_dev_put() for the normal and error path.
--- drivers/char/hw_random/amd-rng.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-)
drivers/char/hw_random/amd-rng.c +13 -5
@@ -143,15 +143,19 @@ static int __init mod_init(void) found: err =pci_read_config_dword (pdev,0x58 , &pmbase);if (err) -return err; + goto put_dev; pmbase &=0x0000FF00 ; -if (pmbase ==0 ) -return -EIO ; +if (pmbase ==0 ) { + err = -EIO ; + goto put_dev; + } priv =kzalloc (sizeof (*priv),GFP_KERNEL ); -if (!priv) -return -ENOMEM ; +if (!priv) { + err = -ENOMEM ; + goto put_dev; + }if (!request_region (pmbase +PMBASE_OFFSET ,PMBASE_SIZE ,DRV_NAME )) { dev_err(&pdev->dev, DRV_NAME " region 0x%x already in use!\n",
@@ -185,6 +189,8 @@ static int __init mod_init(void)release_region (pmbase +PMBASE_OFFSET ,PMBASE_SIZE ); out:kfree (priv); +put_dev: +pci_dev_put (pdev);return err; }
@@ -200,6 +206,8 @@ static void __exit mod_exit(void)release_region (priv->pmbase +PMBASE_OFFSET ,PMBASE_SIZE ); +pci_dev_put (priv->pcidev); +kfree (priv); }
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 339/783 hwrng: geode - Fix PCI device refcount leak
In reply to Greg Kroah-HartmanFrom: Xiongfeng Wang <[email protected]>
[ Upstream commit 9f6ec8dc574efb7f4f3d7ee9cd59ae307e78f445 ]
for_each_pci_dev() is implemented by pci_get_device(). The comment of pci_get_device() says that it will increase the reference count for the returned pci_dev and also decrease the reference count for the input pci_dev @from if it is not NULL.
If we break for_each_pci_dev() loop with pdev not NULL, we need to call pci_dev_put() to decrease the reference count. We add a new struct 'amd_geode_priv' to record pointer of the pci_dev and membase, and then add missing pci_dev_put() for the normal and error path.
--- drivers/char/hw_random/geode-rng.c | 36 +++++++++++++++++++++++------- 1 file changed, 28 insertions(+), 8 deletions(-)
drivers/char/hw_random/geode-rng.c +28 -8
@@ -51,6 +51,10 @@ static const struct pci_device_id pci_tbl[] = { };MODULE_DEVICE_TABLE (pci, pci_tbl); +struct amd_geode_priv { +struct pci_dev *pcidev; +void __iomem *membase; +};static int geode_rng_data_read (struct hwrng *rng,u32 *data) {
@@ -90,6 +94,7 @@ static int __init mod_init(void)const struct pci_device_id *ent;void __iomem *mem;unsigned long rng_base; +struct amd_geode_priv *priv;for_each_pci_dev (pdev) { ent =pci_match_id (pci_tbl, pdev);
@@ -97,17 +102,26 @@ static int __init mod_init(void) goto found; }/* Device not found. */ - goto out; +return err; found: + priv =kzalloc (sizeof (*priv),GFP_KERNEL ); +if (!priv) { + err = -ENOMEM ; + goto put_dev; + } + rng_base =pci_resource_start (pdev,0 );if (rng_base ==0 ) - goto out; + goto free_priv; err = -ENOMEM ; mem =ioremap (rng_base,0x58 );if (!mem) - goto out; - geode_rng.priv = (unsigned long )mem; + goto free_priv; + + geode_rng.priv = (unsigned long )priv; + priv->membase = mem; + priv->pcidev = pdev;pr_info ("AMD Geode RNG detected\n" ); err =hwrng_register (&geode_rng);
@@ -116,20 +130,26 @@ static int __init mod_init(void) err); goto err_unmap; } -out:return err; err_unmap:iounmap (mem); - goto out; +free_priv: +kfree (priv); +put_dev: +pci_dev_put (pdev); +return err; } static void __exit mod_exit(void) { -void __iomem *mem = (void __iomem *)geode_rng.priv; +struct amd_geode_priv *priv; + priv = (struct amd_geode_priv *)geode_rng.priv;hwrng_unregister (&geode_rng); -iounmap (mem); +iounmap (priv->membase); +pci_dev_put (priv->pcidev); +kfree (priv); }module_init (mod_init);
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 340/783 IB/IPoIB: Fix queue count inconsistency for PKEY child interfaces
In reply to Greg Kroah-HartmanFrom: Dragos Tatulea <[email protected]>
[ Upstream commit dbc94a0fb81771a38733c0e8f2ea8c4fa6934dc1 ]
There are 2 ways to create IPoIB PKEY child interfaces:
1) Writing a PKEY to /sys/class/net/<ib parent interface>/create_child.
2) Using netlink with iproute.
While with sysfs the child interface has the same number of tx and rx queues as the parent, with netlink there will always be 1 tx and 1 rx queue for the child interface. That's because the get_num_tx/rx_queues() netlink ops are missing and the default value of 1 is taken for the number of queues (in rtnl_create_link()).
This change adds the get_num_tx/rx_queues() ops which allows for interfaces with multiple queues to be created over netlink. This constant only represents the max number of tx and rx queues on that net device.
--- drivers/infiniband/ulp/ipoib/ipoib_netlink.c | 7 +++++++ 1 file changed, 7 insertions(+)
drivers/infiniband/ulp/ipoib/ipoib_netlink.c +7 -0
@@ -42,6 +42,11 @@ static const struct nla_policy ipoib_policy[IFLA_IPOIB_MAX + 1] = { [IFLA_IPOIB_UMCAST] = { .type = NLA_U16 }, }; +static unsigned int ipoib_get_max_num_queues (void ) +{ + return min_t(unsigned int, num_possible_cpus(), 128); +} +static int ipoib_fill_info (struct sk_buff *skb,const struct net_device *dev) {struct ipoib_dev_priv *priv =ipoib_priv (dev);
@@ -173,6 +178,8 @@ static struct rtnl_link_ops ipoib_link_ops __read_mostly = { .changelink = ipoib_changelink, .get_size = ipoib_get_size, .fill_info = ipoib_fill_info, + .get_num_rx_queues = ipoib_get_max_num_queues, + .get_num_tx_queues = ipoib_get_max_num_queues, };struct rtnl_link_ops *ipoib_get_link_ops (void )
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 341/783 drivers: dio: fix possible memory leak in dio_init()
In reply to Greg Kroah-HartmanFrom: Yang Yingliang <[email protected]>
[ Upstream commit e63e99397b2613d50a5f4f02ed07307e67a190f1 ]
If device_register() returns error, the 'dev' and name needs be freed. Add a release function, and then call put_device() in the error path, so the name is freed in kobject_cleanup() and to the 'dev' is freed in release function.
--- drivers/dio/dio.c | 8 ++++++++ 1 file changed, 8 insertions(+)
drivers/dio/dio.c +8 -0
@@ -110,6 +110,12 @@ static char dio_no_name[] = { 0 };#endif /* CONFIG_DIO_CONSTANTS */ +static void dio_dev_release (struct device *dev) +{ + struct dio_dev *ddev = container_of(dev, typeof(struct dio_dev), dev); +kfree (ddev); +} +int __init dio_find (int deviceid) {/* Called to find a DIO device before the full bus scan has run.
@@ -224,6 +230,7 @@ static int __init dio_init(void) dev->bus = &dio_bus; dev->dev.parent = &dio_bus.dev; dev->dev.bus = &dio_bus_type; + dev->dev.release = dio_dev_release; dev->scode = scode; dev->resource.start = pa; dev->resource.end = pa +DIO_SIZE (scode, va);
@@ -251,6 +258,7 @@ static int __init dio_init(void)if (error) {pr_err ("DIO: Error registering device %s\n" , dev->name); +put_device (&dev->dev);continue ; } error =dio_create_sysfs_dev_files (dev);
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 342/783 serial: tegra: Read DMA status before terminating
In reply to Greg Kroah-HartmanFrom: Kartik <[email protected]>
[ Upstream commit 109a951a9f1fd8a34ebd1896cbbd5d5cede880a7 ]
Read the DMA status before terminating the DMA, as doing so deletes the DMA desc.
Also, to get the correct transfer status information, pause the DMA using dmaengine_pause() before reading the DMA status.
--- drivers/tty/serial/serial-tegra.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/tty/serial/serial-tegra.c +4 -2
@@ -614,8 +614,9 @@ static void tegra_uart_stop_tx(struct uart_port *u)if (tup->tx_in_progress !=TEGRA_UART_TX_DMA )return ; -dmaengine_terminate_all (tup->tx_dma_chan); +dmaengine_pause (tup->tx_dma_chan);dmaengine_tx_status (tup->tx_dma_chan, tup->tx_cookie, &state); +dmaengine_terminate_all (tup->tx_dma_chan); count = tup->tx_bytes_requested - state.residue;async_tx_ack (tup->tx_dma_desc);uart_xmit_advance (&tup->uport, count);
@@ -758,8 +759,9 @@ static void tegra_uart_terminate_rx_dma(struct tegra_uart_port *tup)return ; } -dmaengine_terminate_all (tup->rx_dma_chan); +dmaengine_pause (tup->rx_dma_chan);dmaengine_tx_status (tup->rx_dma_chan, tup->rx_cookie, &state); +dmaengine_terminate_all (tup->rx_dma_chan);tegra_uart_rx_buffer_push (tup, state.residue); tup->rx_dma_active = false;
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 343/783 class: fix possible memory leak in __class_register()
In reply to Greg Kroah-HartmanFrom: Yang Yingliang <[email protected]>
[ Upstream commit 8c3e8a6bdb5253b97ad532570f8b5db5f7a06407 ]
If class_add_groups() returns error, the 'cp->subsys' need be unregister, and the 'cp' need be freed.
We can not call kset_unregister() here, because the 'cls' will be freed in callback function class_release() and it's also freed in caller's error path, it will cause double free.
So fix this by calling kobject_del() and kfree_const(name) to cleanup kobject. Besides, call kfree() to free the 'cp'.
Fault injection test can trigger this:
unreferenced object 0xffff888102fa8190 (size 8):
comm "modprobe", pid 502, jiffies 4294906074 (age 49.296s) hex dump (first 8 bytes):
70 6b 74 63 64 76 64 00 pktcdvd.
backtrace:
[<00000000e7c7703d>] __kmalloc_track_caller+0x1ae/0x320
[<000000005e4d70bc>] kstrdup+0x3a/0x70
[<00000000c2e5e85a>] kstrdup_const+0x68/0x80
[<000000000049a8c7>] kvasprintf_const+0x10b/0x190
[<0000000029123163>] kobject_set_name_vargs+0x56/0x150
[<00000000747219c9>] kobject_set_name+0xab/0xe0
[<0000000005f1ea4e>] __class_register+0x15c/0x49aunreferenced object 0xffff888037274000 (size 1024):
comm "modprobe", pid 502, jiffies 4294906074 (age 49.296s) hex dump (first 32 bytes):
00 40 27 37 80 88 ff ff 00 40 27 37 80 88 ff ff .@'7.....@'7....
00 00 00 00 ad 4e ad de ff ff ff ff 00 00 00 00 .....N..........
backtrace:
[<00000000151f9600>] kmem_cache_alloc_trace+0x17c/0x2f0
[<00000000ecf3dd95>] __class_register+0x86/0x49a--- drivers/base/class.c | 5 +++++ 1 file changed, 5 insertions(+)
drivers/base/class.c +5 -0
@@ -192,6 +192,11 @@ int __class_register(struct class *cls, struct lock_class_key *key) } error =class_add_groups (class_get (cls), cls->class_groups);class_put (cls); +if (error) { +kobject_del (&cp->subsys.kobj); +kfree_const (cp->subsys.kobj.name); +kfree (cp); + }return error; }EXPORT_SYMBOL_GPL (__class_register);
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 344/783 vfio: platform: Do not pass return buffer to ACPI _RST method
In reply to Greg Kroah-HartmanFrom: Rafael Mendonca <[email protected]>
[ Upstream commit e67e070632a665c932d534b8b800477bb3111449 ]
The ACPI _RST method has no return value, there's no need to pass a return buffer to acpi_evaluate_object().
--- drivers/vfio/platform/vfio_platform_common.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/vfio/platform/vfio_platform_common.c +1 -2
@@ -72,12 +72,11 @@ static int vfio_platform_acpi_call_reset(struct vfio_platform_device *vdev, const char **extra_dbg) {#ifdef CONFIG_ACPI -struct acpi_buffer buffer = {ACPI_ALLOCATE_BUFFER ,NULL };struct device *dev = vdev->device;acpi_handle handle =ACPI_HANDLE (dev);acpi_status acpi_ret; - acpi_ret =acpi_evaluate_object (handle,"_RST" ,NULL , &buffer); + acpi_ret =acpi_evaluate_object (handle,"_RST" ,NULL ,NULL );if (ACPI_FAILURE (acpi_ret)) {if (extra_dbg) *extra_dbg =acpi_format_exception (acpi_ret);
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 345/783 uio: uio_dmem_genirq: Fix missing unlock in irq configuration
In reply to Greg Kroah-HartmanFrom: Rafael Mendonca <[email protected]>
[ Upstream commit 9de255c461d1b3f0242b3ad1450c3323a3e00b34 ]
Commit b74351287d4b ("uio: fix a sleep-in-atomic-context bug in uio_dmem_genirq_irqcontrol()") started calling disable_irq() without holding the spinlock because it can sleep. However, that fix introduced another bug: if interrupt is already disabled and a new disable request comes in, then the spinlock is not unlocked:
root@localhost:~# printf '\x00\x00\x00\x00' > /dev/uio0 root@localhost:~# printf '\x00\x00\x00\x00' > /dev/uio0 root@localhost:~# [ 14.851538] BUG: scheduling while atomic: bash/223/0x00000002 [ 14.851991] Modules linked in: uio_dmem_genirq uio myfpga(OE) bochs drm_vram_helper drm_ttm_helper ttm drm_kms_helper drm snd_pcm ppdev joydev psmouse snd_timer snd e1000fb_sys_fops syscopyarea parport sysfillrect soundcore sysimgblt input_leds pcspkr i2c_piix4 serio_raw floppy evbug qemu_fw_cfg mac_hid pata_acpi ip_tables x_tables autofs4 [last unloaded: parport_pc] [ 14.854206] CPU: 0 PID: 223 Comm: bash Tainted: G OE 6.0.0-rc7 #21 [ 14.854786] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS rel-1.16.0-0-gd239552ce722-prebuilt.qemu.org 04/01/2014 [ 14.855664] Call Trace: [ 14.855861] <TASK> [ 14.856025] dump_stack_lvl+0x4d/0x67 [ 14.856325] dump_stack+0x14/0x1a [ 14.856583] __schedule_bug.cold+0x4b/0x5c [ 14.856915] __schedule+0xe81/0x13d0 [ 14.857199] ? idr_find+0x13/0x20 [ 14.857456] ? get_work_pool+0x2d/0x50 [ 14.857756] ? __flush_work+0x233/0x280 [ 14.858068] ? __schedule+0xa95/0x13d0 [ 14.858307] ? idr_find+0x13/0x20 [ 14.858519] ? get_work_pool+0x2d/0x50 [ 14.858798] schedule+0x6c/0x100 [ 14.859009] schedule_hrtimeout_range_clock+0xff/0x110 [ 14.859335] ? tty_write_room+0x1f/0x30 [ 14.859598] ? n_tty_poll+0x1ec/0x220 [ 14.859830] ? tty_ldisc_deref+0x1a/0x20 [ 14.860090] schedule_hrtimeout_range+0x17/0x20 [ 14.860373] do_select+0x596/0x840 [ 14.860627] ? __kernel_text_address+0x16/0x50 [ 14.860954] ? poll_freewait+0xb0/0xb0 [ 14.861235] ? poll_freewait+0xb0/0xb0 [ 14.861517] ? rpm_resume+0x49d/0x780 [ 14.861798] ? common_interrupt+0x59/0xa0 [ 14.862127] ? asm_common_interrupt+0x2b/0x40 [ 14.862511] ? __uart_start.isra.0+0x61/0x70 [ 14.862902] ? __check_object_size+0x61/0x280 [ 14.863255] core_sys_select+0x1c6/0x400 [ 14.863575] ? vfs_write+0x1c9/0x3d0 [ 14.863853] ? vfs_write+0x1c9/0x3d0 [ 14.864121] ? _copy_from_user+0x45/0x70 [ 14.864526] do_pselect.constprop.0+0xb3/0xf0 [ 14.864893] ? do_syscall_64+0x6d/0x90 [ 14.865228] ? do_syscall_64+0x6d/0x90 [ 14.865556] __x64_sys_pselect6+0x76/0xa0 [ 14.865906] do_syscall_64+0x60/0x90 [ 14.866214] ? syscall_exit_to_user_mode+0x2a/0x50 [ 14.866640] ? do_syscall_64+0x6d/0x90 [ 14.866972] ? do_syscall_64+0x6d/0x90 [ 14.867286] ? do_syscall_64+0x6d/0x90 [ 14.867626] entry_SYSCALL_64_after_hwframe+0x63/0xcd [...] stripped [ 14.872959] </TASK>
('myfpga' is a simple 'uio_dmem_genirq' driver I wrote to test this)
The implementation of "uio_dmem_genirq" was based on "uio_pdrv_genirq" and it is used in a similar manner to the "uio_pdrv_genirq" driver with respect to interrupt configuration and handling. At the time "uio_dmem_genirq" was introduced, both had the same implementation of the 'uio_info' handlers irqcontrol() and handler(). Then commit 34cb27528398 ("UIO: Fix concurrency issue"), which was only applied to "uio_pdrv_genirq", ended up making them a little different. That commit, among other things, changed disable_irq() to disable_irq_nosync() in the implementation of irqcontrol(). The motivation there was to avoid a deadlock between irqcontrol() and handler(), since it added a spinlock in the irq handler, and disable_irq() waits for the completion of the irq handler.
By changing disable_irq() to disable_irq_nosync() in irqcontrol(), we also avoid the sleeping-while-atomic bug that commit b74351287d4b ("uio: fix a sleep-in-atomic-context bug in uio_dmem_genirq_irqcontrol()") was trying to fix. Thus, this fixes the missing unlock in irqcontrol() by importing the implementation of irqcontrol() handler from the "uio_pdrv_genirq" driver. In the end, it reverts commit b74351287d4b ("uio: fix a sleep-in-atomic-context bug in uio_dmem_genirq_irqcontrol()") and change disable_irq() to disable_irq_nosync().
It is worth noting that this still does not address the concurrency issue fixed by commit 34cb27528398 ("UIO: Fix concurrency issue"). It will be addressed separately in the next commits.
Split out from commit 34cb27528398 ("UIO: Fix concurrency issue").
--- drivers/uio/uio_dmem_genirq.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-)
drivers/uio/uio_dmem_genirq.c +3 -5
@@ -132,13 +132,11 @@ static int uio_dmem_genirq_irqcontrol(struct uio_info *dev_info, s32 irq_on)if (irq_on) {if (test_and_clear_bit (0 , &priv->flags))enable_irq (dev_info->irq); -spin_unlock_irqrestore (&priv->lock, flags); }else { -if (!test_and_set_bit (0 , &priv->flags)) { -spin_unlock_irqrestore (&priv->lock, flags); -disable_irq (dev_info->irq); - } +if (!test_and_set_bit (0 , &priv->flags)) +disable_irq_nosync (dev_info->irq); } +spin_unlock_irqrestore (&priv->lock, flags);return 0 ; }
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 346/783 uio: uio_dmem_genirq: Fix deadlock between irq config and handling
In reply to Greg Kroah-HartmanFrom: Rafael Mendonca <[email protected]>
[ Upstream commit 118b918018175d9fcd8db667f905012e986cc2c9 ]
This fixes a concurrency issue addressed in commit 34cb27528398 ("UIO: Fix concurrency issue"):
"In a SMP case there was a race condition issue between Uio_pdrv_genirq_irqcontrol() running on one CPU and irq handler on another CPU. Fix it by spin_locking shared resources access inside irq handler."
The implementation of "uio_dmem_genirq" was based on "uio_pdrv_genirq" and it is used in a similar manner to the "uio_pdrv_genirq" driver with respect to interrupt configuration and handling. At the time "uio_dmem_genirq" was merged, both had the same implementation of the 'uio_info' handlers irqcontrol() and handler(), thus, both had the same concurrency issue mentioned by the above commit. However, the above patch was only applied to the "uio_pdrv_genirq" driver.
Split out from commit 34cb27528398 ("UIO: Fix concurrency issue").
--- drivers/uio/uio_dmem_genirq.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/uio/uio_dmem_genirq.c +4 -1
@@ -110,8 +110,10 @@ static irqreturn_t uio_dmem_genirq_handler(int irq, struct uio_info *dev_info)* remember the state so we can allow user space to enable it later. */ +spin_lock (&priv->lock);if (!test_and_set_bit (0 , &priv->flags))disable_irq_nosync (irq); +spin_unlock (&priv->lock);return IRQ_HANDLED ; }
@@ -125,7 +127,8 @@ static int uio_dmem_genirq_irqcontrol(struct uio_info *dev_info, s32 irq_on)* in the interrupt controller, but keep track of the * state to prevent per-irq depth damage. * -* Serialize this operation to support multiple tasks. +* Serialize this operation to support multiple tasks and concurrency +* with irq handler on SMP systems. */ spin_lock_irqsave (&priv->lock, flags);
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 347/783 usb: fotg210-udc: Fix ages old endianness issues
In reply to Greg Kroah-HartmanFrom: Linus Walleij <[email protected]>
[ Upstream commit 46ed6026ca2181c917c8334a82e3eaf40a6234dd ]
The code in the FOTG210 driver isn't entirely endianness-agnostic as reported by the kernel robot sparse testing. This came to the surface while moving the files around.
The driver is only used on little-endian systems, so this causes no real-world regression, but it is nice to be strict and have some compile coverage also on big endian machines, so fix it up with the right LE accessors.
--- drivers/usb/gadget/udc/fotg210-udc.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
drivers/usb/gadget/udc/fotg210-udc.c +6 -6
@@ -629,10 +629,10 @@ static void fotg210_request_error(struct fotg210_udc *fotg210)static void fotg210_set_address (struct fotg210_udc *fotg210,struct usb_ctrlrequest *ctrl) { -if (ctrl->wValue >=0x0100 ) { +if (le16_to_cpu (ctrl->wValue) >=0x0100 ) {fotg210_request_error (fotg210); }else { -fotg210_set_dev_addr (fotg210, ctrl->wValue); +fotg210_set_dev_addr (fotg210,le16_to_cpu (ctrl->wValue));fotg210_set_cxdone (fotg210); } }
@@ -713,17 +713,17 @@ static void fotg210_get_status(struct fotg210_udc *fotg210,switch (ctrl->bRequestType &USB_RECIP_MASK ) {case USB_RECIP_DEVICE : - fotg210->ep0_data =1 <<USB_DEVICE_SELF_POWERED ; + fotg210->ep0_data =cpu_to_le16 (1 <<USB_DEVICE_SELF_POWERED );break ;case USB_RECIP_INTERFACE : - fotg210->ep0_data =0 ; + fotg210->ep0_data =cpu_to_le16 (0 );break ;case USB_RECIP_ENDPOINT : epnum = ctrl->wIndex &USB_ENDPOINT_NUMBER_MASK ;if (epnum) fotg210->ep0_data = -fotg210_is_epnstall (fotg210->ep[epnum]) - <<USB_ENDPOINT_HALT ; +cpu_to_le16 (fotg210_is_epnstall (fotg210->ep[epnum]) + <<USB_ENDPOINT_HALT );else fotg210_request_error (fotg210);break ;
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 348/783 staging: vme_user: Fix possible UAF in tsi148_dma_list_add
In reply to Greg Kroah-HartmanFrom: Gaosheng Cui <[email protected]>
[ Upstream commit 357057ee55d3c99a5de5abe8150f7bca04f8e53b ]
Smatch report warning as follows:
drivers/staging/vme_user/vme_tsi148.c:1757 tsi148_dma_list_add() warn:
'&entry->list' not removed from list
In tsi148_dma_list_add(), the error path "goto err_dma" will not remove entry->list from list->entries, but entry will be freed, then list traversal may cause UAF.
Fix by removeing it from list->entries before free().
--- drivers/vme/bridges/vme_tsi148.c | 1 + 1 file changed, 1 insertion(+)
drivers/vme/bridges/vme_tsi148.c +1 -0
@@ -1771,6 +1771,7 @@ static int tsi148_dma_list_add(struct vme_dma_list *list,return 0 ; err_dma: +list_del (&entry->list); err_dest: err_source: err_align:
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 349/783 usb: typec: Check for ops->exit instead of ops->enter in altmode_exit
In reply to Greg Kroah-HartmanFrom: Sven Peter <[email protected]>
[ Upstream commit b6ddd180e3d9f92c1e482b3cdeec7dda086b1341 ]
typec_altmode_exit checks if ops->enter is not NULL but then calls ops->exit a few lines below. Fix that and check for the function pointer it's about to call instead.
--- drivers/usb/typec/bus.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/usb/typec/bus.c +1 -1
@@ -132,7 +132,7 @@ int typec_altmode_exit(struct typec_altmode *adev)if (!adev || !adev->active)return 0 ; -if (!pdev->ops || !pdev->ops->enter) +if (!pdev->ops || !pdev->ops->exit)return -EOPNOTSUPP ;/* Moving to USB Safe State */
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 350/783 usb: typec: tcpci: fix of node refcount leak in tcpci_register_port()
In reply to Greg Kroah-HartmanFrom: Yang Yingliang <[email protected]>
[ Upstream commit 0384e87e3fec735e47f1c133c796f32ef7a72a9b ]
I got the following report while doing device(mt6370-tcpc) load test with CONFIG_OF_UNITTEST and CONFIG_OF_DYNAMIC enabled:
OF: ERROR: memory leak, expected refcount 1 instead of 2, of_node_get()/of_node_put() unbalanced - destroy cset entry:
attach overlay node /i2c/pmic@34/tcpc/connector
The 'fwnode' set in tcpci_parse_config() which is called in tcpci_register_port(), its node refcount is increased in device_get_named_child_node(). It needs be put while exiting, so call fwnode_handle_put() in the error path of tcpci_register_port() and in tcpci_unregister_port() to avoid leak.
--- drivers/usb/typec/tcpm/tcpci.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/usb/typec/tcpm/tcpci.c +4 -1
@@ -649,8 +649,10 @@ struct tcpci *tcpci_register_port(struct device *dev, struct tcpci_data *data)return ERR_PTR (err); tcpci->port =tcpm_register_port (tcpci->dev, &tcpci->tcpc); -if (IS_ERR (tcpci->port)) +if (IS_ERR (tcpci->port)) { +fwnode_handle_put (tcpci->tcpc.fwnode);return ERR_CAST (tcpci->port); + }return tcpci; }
@@ -659,6 +661,7 @@ EXPORT_SYMBOL_GPL(tcpci_register_port);void tcpci_unregister_port (struct tcpci *tcpci) {tcpm_unregister_port (tcpci->port); +fwnode_handle_put (tcpci->tcpc.fwnode); }EXPORT_SYMBOL_GPL (tcpci_unregister_port);
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 351/783 usb: typec: tipd: Fix spurious fwnode_handle_put in error path
In reply to Greg Kroah-HartmanFrom: Sven Peter <[email protected]>
[ Upstream commit 782c70edc4852a5d39be12377a85501546236212 ]
The err_role_put error path always calls fwnode_handle_put to release the fwnode. This path can be reached after probe itself has already released that fwnode though. Fix that by moving fwnode_handle_put in the happy path to the very end.
--- drivers/usb/typec/tps6598x.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/usb/typec/tps6598x.c +1 -1
@@ -564,7 +564,6 @@ static int tps6598x_probe(struct i2c_client *client) ret =PTR_ERR (tps->port); goto err_role_put; } -fwnode_handle_put (fwnode);if (status &TPS_STATUS_PLUG_PRESENT ) { ret =tps6598x_connect (tps, status);
@@ -583,6 +582,7 @@ static int tps6598x_probe(struct i2c_client *client) }i2c_set_clientdata (client, tps); +fwnode_handle_put (fwnode);return 0 ;
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 352/783 serial: amba-pl011: avoid SBSA UART accessing DMACR register
In reply to Greg Kroah-HartmanFrom: Jiamei Xie <[email protected]>
[ Upstream commit 94cdb9f33698478b0e7062586633c42c6158a786 ]
Chapter "B Generic UART" in "ARM Server Base System Architecture" [1] documentation describes a generic UART interface. Such generic UART does not support DMA. In current code, sbsa_uart_pops and amba_pl011_pops share the same stop_rx operation, which will invoke pl011_dma_rx_stop, leading to an access of the DMACR register. This commit adds a using_rx_dma check in pl011_dma_rx_stop to avoid the access to DMACR register for SBSA UARTs which does not support DMA.
When the kernel enables DMA engine with "CONFIG_DMA_ENGINE=y", Linux
SBSA PL011 driver will access PL011 DMACR register in some functions.
For most real SBSA Pl011 hardware implementations, the DMACR write
behaviour will be ignored. So these DMACR operations will not cause
obvious problems. But for some virtual SBSA PL011 hardware, like Xen
virtual SBSA PL011 (vpl011) device, the behaviour might be different.
Xen vpl011 emulation will inject a data abort to guest, when guest is
accessing an unimplemented UART register. As Xen VPL011 is SBSA
compatible, it will not implement DMACR register. So when Linux SBSA
PL011 driver access DMACR register, it will get an unhandled data abort
fault and the application will get a segmentation fault:
Unhandled fault at 0xffffffc00944d048
Mem abort info:
ESR = 0x96000000
EC = 0x25: DABT (current EL), IL = 32 bits
SET = 0, FnV = 0
EA = 0, S1PTW = 0
FSC = 0x00: ttbr address size fault
Data abort info:
ISV = 0, ISS = 0x00000000
CM = 0, WnR = 0
swapper pgtable: 4k pages, 39-bit VAs, pgdp=0000000020e2e000
[ffffffc00944d048] pgd=100000003ffff803, p4d=100000003ffff803, pud=100000003ffff803, pmd=100000003fffa803, pte=006800009c090f13
Internal error: ttbr address size fault: 96000000 [#1] PREEMPT SMP ... Call trace: pl011_stop_rx+0x70/0x80 tty_port_shutdown+0x7c/0xb4 tty_port_close+0x60/0xcc uart_close+0x34/0x8c tty_release+0x144/0x4c0 __fput+0x78/0x220 ____fput+0x1c/0x30 task_work_run+0x88/0xc0 do_notify_resume+0x8d0/0x123c el0_svc+0xa8/0xc0 el0t_64_sync_handler+0xa4/0x130 el0t_64_sync+0x1a0/0x1a4 Code: b9000083 b901f001 794038a0 8b000042 (b9000041) ---[ end trace 83dd93df15c3216f ]---
note: bootlogd[132] exited with preempt_count 1 /etc/rcS.d/S07bootlogd: line 47: 132 Segmentation fault start-stop-daemon
This has been discussed in the Xen community, and we think it should fix this in Linux. See [2] for more information.
[1] https://developer.arm.com/documentation/den0094/c/?lang=en
[2] https://lists.xenproject.org/archives/html/xen-devel/2022-11/msg00543.html
--- drivers/tty/serial/amba-pl011.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/tty/serial/amba-pl011.c +3 -0
@@ -1048,6 +1048,9 @@ static void pl011_dma_rx_callback(void *data)*/ static inline void pl011_dma_rx_stop (struct uart_amba_port *uap) { +if (!uap->using_rx_dma) +return ; +/* FIXME. Just disable the DMA enable */ uap->dmacr &= ~UART011_RXDMAE ;pl011_write (uap->dmacr, uap,REG_DMACR );
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 353/783 serial: pl011: Do not clear RX FIFO & RX interrupt in unthrottle.
In reply to Greg Kroah-HartmanFrom: delisun <[email protected]>
[ Upstream commit 032d5a71ed378ffc6a2d41a187d8488a4f9fe415 ]
Clearing the RX FIFO will cause data loss.
Copy the pl011_enabl_interrupts implementation, and remove the clear interrupt and FIFO part of the code.
--- drivers/tty/serial/amba-pl011.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)
drivers/tty/serial/amba-pl011.c +10 -1
@@ -1760,8 +1760,17 @@ static void pl011_enable_interrupts(struct uart_amba_port *uap)static void pl011_unthrottle_rx (struct uart_port *port) { struct uart_amba_port *uap = container_of(port, struct uart_amba_port, port); +unsigned long flags; -pl011_enable_interrupts (uap); +spin_lock_irqsave (&uap->port.lock, flags); + + uap->im =UART011_RTIM ; +if (!pl011_dma_rx_running (uap)) + uap->im |=UART011_RXIM ; + +pl011_write (uap->im, uap,REG_IMSC ); + +spin_unlock_irqrestore (&uap->port.lock, flags); }static int pl011_startup (struct uart_port *port)
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 354/783 serial: pch: Fix PCI device refcount leak in pch_request_dma()
In reply to Greg Kroah-HartmanFrom: Xiongfeng Wang <[email protected]>
[ Upstream commit 8be3a7bf773700534a6e8f87f6ed2ed111254be5 ]
As comment of pci_get_slot() says, it returns a pci_device with its refcount increased. The caller must decrement the reference count by calling pci_dev_put().
Since 'dma_dev' is only used to filter the channel in filter(), we can call pci_dev_put() before exiting from pch_request_dma(). Add the missing pci_dev_put() for the normal and error path.
--- drivers/tty/serial/pch_uart.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/tty/serial/pch_uart.c +4 -0
@@ -711,6 +711,7 @@ static void pch_request_dma(struct uart_port *port)if (!chan) {dev_err (priv->port.dev,"%s:dma_request_channel FAILS(Tx)\n" , __func__); +pci_dev_put (dma_dev);return ; } priv->chan_tx = chan;
@@ -727,6 +728,7 @@ static void pch_request_dma(struct uart_port *port) __func__);dma_release_channel (priv->chan_tx); priv->chan_tx =NULL ; +pci_dev_put (dma_dev);return ; }
@@ -734,6 +736,8 @@ static void pch_request_dma(struct uart_port *port) priv->rx_buf_virt =dma_alloc_coherent (port->dev, port->fifosize, &priv->rx_buf_dma,GFP_KERNEL ); priv->chan_rx = chan; + +pci_dev_put (dma_dev); }static void pch_dma_rx_complete (void *arg)
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 355/783 tty: serial: clean up stop-tx part in altera_uart_tx_chars()
In reply to Greg Kroah-HartmanFrom: Jiri Slaby <[email protected]>
[ Upstream commit d9c128117da41cf4cb0e80ae565b5d3ac79dffac ]
The "stop TX" path in altera_uart_tx_chars() is open-coded, so:
* use uart_circ_empty() to check if the buffer is empty, and
* when true, call altera_uart_stop_tx().
Stable-dep-of: 1307c5d33cce ("serial: altera_uart: fix locking in polling mode")
--- drivers/tty/serial/altera_uart.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/tty/serial/altera_uart.c +2 -4
@@ -274,10 +274,8 @@ static void altera_uart_tx_chars(struct altera_uart *pp)if (uart_circ_chars_pending (xmit) <WAKEUP_CHARS )uart_write_wakeup (port); -if (xmit->head == xmit->tail) { - pp->imr &= ~ALTERA_UART_CONTROL_TRDY_MSK ; -altera_uart_update_ctrl_reg (pp); - } +if (uart_circ_empty (xmit)) +altera_uart_stop_tx (port); }static irqreturn_t altera_uart_interrupt (int irq,void *data)
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 356/783 tty: serial: altera_uart_{r,t}x_chars() need only uart_port
In reply to Greg Kroah-HartmanFrom: Jiri Slaby <[email protected]>
[ Upstream commit 3af44d9bb0539d5fa27d6159d696fda5f3747bff ]
Both altera_uart_{r,t}x_chars() need only uart_port, not altera_uart. So pass the former from altera_uart_interrupt() directly.
Apart it maybe saves a dereference, this makes the transition of altera_uart_tx_chars() easier to follow in the next patch.
Stable-dep-of: 1307c5d33cce ("serial: altera_uart: fix locking in polling mode")
--- drivers/tty/serial/altera_uart.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-)
drivers/tty/serial/altera_uart.c +4 -6
@@ -199,9 +199,8 @@ static void altera_uart_set_termios(struct uart_port *port,*/ } -static void altera_uart_rx_chars (struct altera_uart *pp) +static void altera_uart_rx_chars (struct uart_port *port) { -struct uart_port *port = &pp->port;unsigned char ch, flag;unsigned short status;
@@ -248,9 +247,8 @@ static void altera_uart_rx_chars(struct altera_uart *pp)spin_lock (&port->lock); } -static void altera_uart_tx_chars (struct altera_uart *pp) +static void altera_uart_tx_chars (struct uart_port *port) { -struct uart_port *port = &pp->port;struct circ_buf *xmit = &port->state->xmit;if (port->x_char) {
@@ -288,9 +286,9 @@ static irqreturn_t altera_uart_interrupt(int irq, void *data)spin_lock (&port->lock);if (isr &ALTERA_UART_STATUS_RRDY_MSK ) -altera_uart_rx_chars (pp); +altera_uart_rx_chars (port);if (isr &ALTERA_UART_STATUS_TRDY_MSK ) -altera_uart_tx_chars (pp); +altera_uart_tx_chars (port);spin_unlock (&port->lock);return IRQ_RETVAL (isr);
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 357/783 serial: altera_uart: fix locking in polling mode
In reply to Greg Kroah-HartmanFrom: Gabriel Somlo <[email protected]>
[ Upstream commit 1307c5d33cce8a41dd77c2571e4df65a5b627feb ]
Since altera_uart_interrupt() may also be called from a poll timer in "serving_softirq" context, use spin_[lock_irqsave|unlock_irqrestore] variants, which are appropriate for both softirq and hardware interrupt contexts.
--- drivers/tty/serial/altera_uart.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/tty/serial/altera_uart.c +3 -2
@@ -280,16 +280,17 @@ static irqreturn_t altera_uart_interrupt(int irq, void *data) {struct uart_port *port = data; struct altera_uart *pp = container_of(port, struct altera_uart, port); +unsigned long flags;unsigned int isr; isr =altera_uart_readl (port,ALTERA_UART_STATUS_REG ) & pp->imr; -spin_lock (&port->lock); +spin_lock_irqsave (&port->lock, flags);if (isr &ALTERA_UART_STATUS_RRDY_MSK )altera_uart_rx_chars (port);if (isr &ALTERA_UART_STATUS_TRDY_MSK )altera_uart_tx_chars (port); -spin_unlock (&port->lock); +spin_unlock_irqrestore (&port->lock, flags);return IRQ_RETVAL (isr); }
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 358/783 serial: sunsab: Fix error handling in sunsab_init()
In reply to Greg Kroah-HartmanFrom: Yuan Can <[email protected]>
[ Upstream commit 1a6ec673fb627c26e2267ca0a03849f91dbd9b40 ]
The sunsab_init() returns the platform_driver_register() directly without checking its return value, if platform_driver_register() failed, the allocated sunsab_ports is leaked.
Fix by free sunsab_ports and set it to NULL when platform_driver_register() failed.
--- drivers/tty/serial/sunsab.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
drivers/tty/serial/sunsab.c +7 -1
@@ -1137,7 +1137,13 @@ static int __init sunsab_init(void) } } -return platform_driver_register (&sab_driver); + err =platform_driver_register (&sab_driver); +if (err) { +kfree (sunsab_ports); + sunsab_ports =NULL ; + } + +return err; } static void __exit sunsab_exit(void)
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 359/783 test_firmware: fix memory leak in test_firmware_init()
In reply to Greg Kroah-HartmanFrom: Zhengchao Shao <[email protected]>
[ Upstream commit 7610615e8cdb3f6f5bbd9d8e7a5d8a63e3cabf2e ]
When misc_register() failed in test_firmware_init(), the memory pointed by test_fw_config->name is not released. The memory leak information is as follows:
unreferenced object 0xffff88810a34cb00 (size 32):
comm "insmod", pid 7952, jiffies 4294948236 (age 49.060s) hex dump (first 32 bytes):
74 65 73 74 2d 66 69 72 6d 77 61 72 65 2e 62 69 test-firmware.bi
6e 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 n...............
backtrace:
[<ffffffff81b21fcb>] __kmalloc_node_track_caller+0x4b/0xc0
[<ffffffff81affb96>] kstrndup+0x46/0xc0
[<ffffffffa0403a49>] __test_firmware_config_init+0x29/0x380 [test_firmware]
[<ffffffffa040f068>] 0xffffffffa040f068
[<ffffffff81002c41>] do_one_initcall+0x141/0x780
[<ffffffff816a72c3>] do_init_module+0x1c3/0x630
[<ffffffff816adb9e>] load_module+0x623e/0x76a0
[<ffffffff816af471>] __do_sys_finit_module+0x181/0x240
[<ffffffff89978f99>] do_syscall_64+0x39/0xb0
[<ffffffff89a0008b>] entry_SYSCALL_64_after_hwframe+0x63/0xcd--- lib/test_firmware.c | 1 + 1 file changed, 1 insertion(+)
lib/test_firmware.c +1 -0
@@ -1114,6 +1114,7 @@ static int __init test_firmware_init(void) rc =misc_register (&test_fw_misc_device);if (rc) { +__test_firmware_config_free ();kfree (test_fw_config);pr_err ("could not register misc device: %d\n" , rc);return rc;
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 360/783 misc: ocxl: fix possible name leak in ocxl_file_register_afu()
In reply to Greg Kroah-HartmanFrom: Yang Yingliang <[email protected]>
[ Upstream commit a4cb1004aeed2ab893a058fad00a5b41a12c4691 ]
If device_register() returns error in ocxl_file_register_afu(), the name allocated by dev_set_name() need be freed. As comment of device_register() says, it should use put_device() to give up the reference in the error path. So fix this by calling put_device(), then the name can be freed in kobject_cleanup(), and info is freed in info_release().
--- drivers/misc/ocxl/file.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
drivers/misc/ocxl/file.c +5 -2
@@ -543,8 +543,11 @@ int ocxl_file_register_afu(struct ocxl_afu *afu) goto err_put; rc =device_register (&info->dev); -if (rc) - goto err_put; +if (rc) { +free_minor (info); +put_device (&info->dev); +return rc; + } rc =ocxl_sysfs_register_afu (info);if (rc)
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 361/783 ocxl: fix pci device refcount leak when calling get_function_0()
In reply to Greg Kroah-HartmanFrom: Yang Yingliang <[email protected]>
[ Upstream commit 27158c72678b39ee01cc01de1aba6b51c71abe2f ]
get_function_0() calls pci_get_domain_bus_and_slot(), as comment says, it returns a pci device with refcount increment, so after using it, pci_dev_put() needs be called.
Get the device reference when get_function_0() is not called, so pci_dev_put() can be called in the error path and callers unconditionally. And add comment above get_dvsec_vendor0() to tell callers to call pci_dev_put().
--- drivers/misc/ocxl/config.c | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-)
drivers/misc/ocxl/config.c +19 -1
@@ -204,6 +204,18 @@ static int read_dvsec_vendor(struct pci_dev *dev)return 0 ; } +/** +* get_dvsec_vendor0() - Find a related PCI device (function 0) +* @dev: PCI device to match +* @dev0: The PCI device (function 0) found +* @out_pos: The position of PCI device (function 0) +* +* Returns 0 on success, negative on failure. +* +* NOTE: If it's successful, the reference of dev0 is increased, +* so after using it, the callers must call pci_dev_put() to give +* up the reference. +*/ static int get_dvsec_vendor0 (struct pci_dev *dev,struct pci_dev **dev0,int *out_pos) {
@@ -213,10 +225,14 @@ static int get_dvsec_vendor0(struct pci_dev *dev, struct pci_dev **dev0, dev =get_function_0 (dev);if (!dev)return -1 ; + }else { + dev =pci_dev_get (dev); } pos =find_dvsec (dev,OCXL_DVSEC_VENDOR_ID ); -if (!pos) +if (!pos) { +pci_dev_put (dev);return -1 ; + } *dev0 = dev; *out_pos = pos;return 0 ;
@@ -233,6 +249,7 @@ int ocxl_config_get_reset_reload(struct pci_dev *dev, int *val)pci_read_config_dword (dev0, pos +OCXL_DVSEC_VENDOR_RESET_RELOAD , &reset_reload); +pci_dev_put (dev0); *val = !!(reset_reload &BIT (0 ));return 0 ; }
@@ -254,6 +271,7 @@ int ocxl_config_set_reset_reload(struct pci_dev *dev, int val) reset_reload &= ~BIT (0 );pci_write_config_dword (dev0, pos +OCXL_DVSEC_VENDOR_RESET_RELOAD , reset_reload); +pci_dev_put (dev0);return 0 ; }
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 362/783 misc: tifm: fix possible memory leak in tifm_7xx1_switch_media()
In reply to Greg Kroah-HartmanFrom: ruanjinjie <[email protected]>
[ Upstream commit fd2c930cf6a5b9176382c15f9acb1996e76e25ad ]
If device_register() returns error in tifm_7xx1_switch_media(), name of kobject which is allocated in dev_set_name() called in device_add() is leaked.
Never directly free @dev after calling device_register(), even if it returned an error! Always use put_device() to give up the reference initialized.
--- drivers/misc/tifm_7xx1.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/misc/tifm_7xx1.c +1 -1
@@ -190,7 +190,7 @@ static void tifm_7xx1_switch_media(struct work_struct *work)spin_unlock_irqrestore (&fm->lock, flags); }if (sock) -tifm_free_device (&sock->dev); +put_device (&sock->dev); }spin_lock_irqsave (&fm->lock, flags); }
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 363/783 misc: sgi-gru: fix use-after-free error in gru_set_context_option, gru_fault and gru_handle_user_call_os
In reply to Greg Kroah-HartmanFrom: Zheng Wang <[email protected]>
[ Upstream commit 643a16a0eb1d6ac23744bb6e90a00fc21148a9dc ]
In some bad situation, the gts may be freed gru_check_chiplet_assignment. The call chain can be gru_unload_context->gru_free_gru_context->gts_drop and kfree finally. However, the caller didn't know if the gts is freed or not and use it afterwards. This will trigger a Use after Free bug.
Fix it by introducing a return value to see if it's in error path or not. Free the gts in caller if gru_check_chiplet_assignment check failed.
--- drivers/misc/sgi-gru/grufault.c | 13 +++++++++++-- drivers/misc/sgi-gru/grumain.c | 22 ++++++++++++++++++---- drivers/misc/sgi-gru/grutables.h | 2 +- 3 files changed, 30 insertions(+), 7 deletions(-)
drivers/misc/sgi-gru/grufault.c +11 -2
@@ -648,6 +648,7 @@ int gru_handle_user_call_os(unsigned long cb)if ((cb & (GRU_HANDLE_STRIDE -1 )) || ucbnum >=GRU_NUM_CB )return -EINVAL ; +again: gts =gru_find_lock_gts (cb);if (!gts)return -EINVAL ;
@@ -656,7 +657,11 @@ int gru_handle_user_call_os(unsigned long cb)if (ucbnum >= gts->ts_cbr_au_count *GRU_CBR_AU_SIZE ) goto exit; -gru_check_context_placement (gts); +if (gru_check_context_placement (gts)) { +gru_unlock_gts (gts); +gru_unload_context (gts,1 ); + goto again; + }/* * CCH may contain stale data if ts_force_cch_reload is set.
@@ -874,7 +879,11 @@ int gru_set_context_option(unsigned long arg) }else { gts->ts_user_blade_id = req.val1; gts->ts_user_chiplet_id = req.val0; -gru_check_context_placement (gts); +if (gru_check_context_placement (gts)) { +gru_unlock_gts (gts); +gru_unload_context (gts,1 ); +return ret; + } }break ;case sco_gseg_owner:
drivers/misc/sgi-gru/grumain.c +18 -4
@@ -716,9 +716,10 @@ static int gru_check_chiplet_assignment(struct gru_state *gru,* chiplet. Misassignment can occur if the process migrates to a different * blade or if the user changes the selected blade/chiplet. */ -void gru_check_context_placement (struct gru_thread_state *gts) +int gru_check_context_placement (struct gru_thread_state *gts) {struct gru_state *gru; +int ret =0 ;/* * If the current task is the context owner, verify that the
@@ -726,15 +727,23 @@ void gru_check_context_placement(struct gru_thread_state *gts)* references. Pthread apps use non-owner references to the CBRs. */ gru = gts->ts_gru; +/* +* If gru or gts->ts_tgid_owner isn't initialized properly, return +* success to indicate that the caller does not need to unload the +* gru context.The caller is responsible for their inspection and +* reinitialization if needed. +*/ if (!gru || gts->ts_tgid_owner != current->tgid) -return ; +return ret;if (!gru_check_chiplet_assignment (gru, gts)) {STAT (check_context_unload); -gru_unload_context (gts,1 ); + ret = -EINVAL ; }else if (gru_retarget_intr (gts)) {STAT (check_context_retarget_intr); } + +return ret; }
@@ -934,7 +943,12 @@ vm_fault_t gru_fault(struct vm_fault *vmf)mutex_lock (>s->ts_ctxlock);preempt_disable (); -gru_check_context_placement (gts); +if (gru_check_context_placement (gts)) { +preempt_enable (); +mutex_unlock (>s->ts_ctxlock); +gru_unload_context (gts,1 ); +return VM_FAULT_NOPAGE ; + }if (!gts->ts_gru) {STAT (load_user_context);
drivers/misc/sgi-gru/grutables.h +1 -1
@@ -637,7 +637,7 @@ extern int gru_user_flush_tlb(unsigned long arg);extern int gru_user_unload_context (unsigned long arg);extern int gru_get_exception_detail (unsigned long arg);extern int gru_set_context_option (unsigned long address); -extern void gru_check_context_placement (struct gru_thread_state *gts); +extern int gru_check_context_placement (struct gru_thread_state *gts);extern int gru_cpu_fault_map_id (void );extern struct vm_area_struct *gru_find_vma (unsigned long vaddr);extern void gru_flush_all_tlb (struct gru_state *gru);
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 364/783 firmware: raspberrypi: fix possible memory leak in rpi_firmware_probe()
In reply to Greg Kroah-HartmanFrom: Yang Yingliang <[email protected]>
[ Upstream commit 7b51161696e803fd5f9ad55b20a64c2df313f95c ]
In rpi_firmware_probe(), if mbox_request_channel() fails, the 'fw' will not be freed through rpi_firmware_delete(), fix this leak by calling kfree() in the error path.
--- drivers/firmware/raspberrypi.c | 1 + 1 file changed, 1 insertion(+)
drivers/firmware/raspberrypi.c +1 -0
@@ -265,6 +265,7 @@ static int rpi_firmware_probe(struct platform_device *pdev)int ret =PTR_ERR (fw->chan);if (ret != -EPROBE_DEFER )dev_err (dev,"Failed to get mbox channel: %d\n" , ret); +kfree (fw);return ret; }
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 365/783 cxl: fix possible null-ptr-deref in cxl_guest_init_afu|adapter()
In reply to Greg Kroah-HartmanFrom: Yang Yingliang <[email protected]>
[ Upstream commit 61c80d1c3833e196256fb060382db94f24d3d9a7 ]
If device_register() fails in cxl_register_afu|adapter(), the device is not added, device_unregister() can not be called in the error path, otherwise it will cause a null-ptr-deref because of removing not added device.
As comment of device_register() says, it should use put_device() to give up the reference in the error path. So split device_unregister() into device_del() and put_device(), then goes to put dev when register fails.
--- drivers/misc/cxl/guest.c | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-)
drivers/misc/cxl/guest.c +14 -10
@@ -959,10 +959,10 @@ int cxl_guest_init_afu(struct cxl *adapter, int slice, struct device_node *afu_n* if it returns an error! */ if ((rc =cxl_register_afu (afu))) - goto err_put1; + goto err_put_dev;if ((rc =cxl_sysfs_afu_add (afu))) - goto err_put1; + goto err_del_dev;/* * pHyp doesn't expose the programming models supported by the
@@ -978,7 +978,7 @@ int cxl_guest_init_afu(struct cxl *adapter, int slice, struct device_node *afu_n afu->modes_supported =CXL_MODE_DIRECTED ;if ((rc =cxl_afu_select_best_mode (afu))) - goto err_put2; + goto err_remove_sysfs; adapter->afu[afu->slice] = afu;
@@ -998,10 +998,12 @@ int cxl_guest_init_afu(struct cxl *adapter, int slice, struct device_node *afu_nreturn 0 ; -err_put2: +err_remove_sysfs:cxl_sysfs_afu_remove (afu); -err_put1: -device_unregister (&afu->dev); +err_del_dev: +device_del (&afu->dev); +err_put_dev: +put_device (&afu->dev); free = false;guest_release_serr_irq (afu); err2:
@@ -1135,18 +1137,20 @@ struct cxl *cxl_guest_init_adapter(struct device_node *np, struct platform_devic* even if it returns an error! */ if ((rc =cxl_register_adapter (adapter))) - goto err_put1; + goto err_put_dev;if ((rc =cxl_sysfs_adapter_add (adapter))) - goto err_put1; + goto err_del_dev;/* release the context lock as the adapter is configured */ cxl_adapter_context_unlock (adapter);return adapter; -err_put1: -device_unregister (&adapter->dev); +err_del_dev: +device_del (&adapter->dev); +err_put_dev: +put_device (&adapter->dev); free = false;cxl_guest_remove_chardev (adapter); err1:
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 366/783 cxl: fix possible null-ptr-deref in cxl_pci_init_afu|adapter()
In reply to Greg Kroah-HartmanFrom: Yang Yingliang <[email protected]>
[ Upstream commit 02cd3032b154fa02fdf90e7467abaeed889330b2 ]
If device_register() fails in cxl_pci_afu|adapter(), the device is not added, device_unregister() can not be called in the error path, otherwise it will cause a null-ptr-deref because of removing not added device.
As comment of device_register() says, it should use put_device() to give up the reference in the error path. So split device_unregister() into device_del() and put_device(), then goes to put dev when register fails.
--- drivers/misc/cxl/pci.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-)
drivers/misc/cxl/pci.c +12 -8
@@ -1164,10 +1164,10 @@ static int pci_init_afu(struct cxl *adapter, int slice, struct pci_dev *dev)* if it returns an error! */ if ((rc =cxl_register_afu (afu))) - goto err_put1; + goto err_put_dev;if ((rc =cxl_sysfs_afu_add (afu))) - goto err_put1; + goto err_del_dev; adapter->afu[afu->slice] = afu;
@@ -1176,10 +1176,12 @@ static int pci_init_afu(struct cxl *adapter, int slice, struct pci_dev *dev)return 0 ; -err_put1: +err_del_dev: +device_del (&afu->dev); +err_put_dev:pci_deconfigure_afu (afu);cxl_debugfs_afu_remove (afu); -device_unregister (&afu->dev); +put_device (&afu->dev);return rc; err_free_native:
@@ -1667,23 +1669,25 @@ static struct cxl *cxl_pci_init_adapter(struct pci_dev *dev)* even if it returns an error! */ if ((rc =cxl_register_adapter (adapter))) - goto err_put1; + goto err_put_dev;if ((rc =cxl_sysfs_adapter_add (adapter))) - goto err_put1; + goto err_del_dev;/* Release the context lock as adapter is configured */ cxl_adapter_context_unlock (adapter);return adapter; -err_put1: +err_del_dev: +device_del (&adapter->dev); +err_put_dev:/* This should mirror cxl_remove_adapter, except without the * sysfs parts */ cxl_debugfs_adapter_remove (adapter);cxl_deconfigure_adapter (adapter); -device_unregister (&adapter->dev); +put_device (&adapter->dev);return ERR_PTR (rc); err_release:
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 367/783 iio: temperature: ltc2983: make bulk write buffer DMA-safe
In reply to Greg Kroah-HartmanFrom: Cosmin Tanislav <[email protected]>
[ Upstream commit 5e0176213949724fbe9a8e4a39817edce337b8a0 ]
regmap_bulk_write() does not guarantee implicit DMA-safety, even though the current implementation duplicates the given buffer. Do not rely on it.
--- drivers/iio/temperature/ltc2983.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
drivers/iio/temperature/ltc2983.c +5 -5
@@ -205,6 +205,7 @@ struct ltc2983_data {* Holds the converted temperature */ __be32 temp____cacheline_aligned ; +__be32 chan_val; };struct ltc2983_sensor {
@@ -309,19 +310,18 @@ static int __ltc2983_fault_handler(const struct ltc2983_data *st,return 0 ; } -static int __ltc2983_chan_assign_common (const struct ltc2983_data *st, +static int __ltc2983_chan_assign_common (struct ltc2983_data *st,const struct ltc2983_sensor *sensor,u32 chan_val) {u32 reg =LTC2983_CHAN_START_ADDR (sensor->chan); -__be32 __chan_val; chan_val |=LTC2983_CHAN_TYPE (sensor->type);dev_dbg (&st->spi->dev,"Assign reg:0x%04X, val:0x%08X\n" , reg, chan_val); - __chan_val =cpu_to_be32 (chan_val); -return regmap_bulk_write (st->regmap, reg, &__chan_val, -sizeof (__chan_val)); + st->chan_val =cpu_to_be32 (chan_val); +return regmap_bulk_write (st->regmap, reg, &st->chan_val, +sizeof (st->chan_val)); } static int __ltc2983_chan_custom_sensor_assign(struct ltc2983_data *st,
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 368/783 genirq: Add IRQF_NO_AUTOEN for request_irq/nmi()
In reply to Greg Kroah-HartmanFrom: Barry Song <[email protected]>
[ Upstream commit cbe16f35bee6880becca6f20d2ebf6b457148552 ]
Many drivers don't want interrupts enabled automatically via request_irq(). So they are handling this issue by either way of the below two:
(1)
irq_set_status_flags(irq, IRQ_NOAUTOEN);
request_irq(dev, irq...);
(2)
request_irq(dev, irq...);
disable_irq(irq);
The code in the second way is silly and unsafe. In the small time gap between request_irq() and disable_irq(), interrupts can still come.
The code in the first way is safe though it's subobtimal.
Add a new IRQF_NO_AUTOEN flag which can be handed in by drivers to request_irq() and request_nmi(). It prevents the automatic enabling of the requested interrupt/nmi in the same safe way as #1 above. With that the various usage sites of #1 and #2 above can be simplified and corrected.
Stable-dep-of: 99c05e4283a1 ("iio: adis: add '__adis_enable_irq()' implementation")
--- include/linux/interrupt.h | 4 ++++ kernel/irq/manage.c | 11 +++++++++-- 2 files changed, 13 insertions(+), 2 deletions(-)
include/linux/interrupt.h +4 -0
@@ -61,6 +61,9 @@* interrupt handler after suspending interrupts. For system * wakeup devices users need to implement wakeup detection in * their interrupt handlers. +* IRQF_NO_AUTOEN - Don't enable IRQ or NMI automatically when users request it. +* Users will enable it explicitly by enable_irq() or enable_nmi() +* later. */ #define IRQF_SHARED 0x00000080#define IRQF_PROBE_SHARED 0x00000100
@@ -74,6 +77,7 @@#define IRQF_NO_THREAD 0x00010000#define IRQF_EARLY_RESUME 0x00020000#define IRQF_COND_SUSPEND 0x00040000 +#define IRQF_NO_AUTOEN 0x00080000#define IRQF_TIMER (__IRQF_TIMER | IRQF_NO_SUSPEND | IRQF_NO_THREAD)
kernel/irq/manage.c +9 -2
@@ -1667,7 +1667,8 @@ __setup_irq(unsigned int irq, struct irq_desc *desc, struct irqaction *new)irqd_set (&desc->irq_data,IRQD_NO_BALANCING ); } -if (irq_settings_can_autoenable (desc)) { +if (!(new->flags &IRQF_NO_AUTOEN ) && +irq_settings_can_autoenable (desc)) {irq_startup (desc,IRQ_RESEND ,IRQ_START_COND ); }else {/*
@@ -2054,10 +2055,15 @@ int request_threaded_irq(unsigned int irq, irq_handler_t handler,* which interrupt is which (messes up the interrupt freeing * logic etc). * +* Also shared interrupts do not go well with disabling auto enable. +* The sharing interrupt might request it while it's still disabled +* and then wait for interrupts forever. +* * Also IRQF_COND_SUSPEND only makes sense for shared interrupts and * it cannot be set along with IRQF_NO_SUSPEND. */ if (((irqflags &IRQF_SHARED ) && !dev_id) || + ((irqflags &IRQF_SHARED ) && (irqflags &IRQF_NO_AUTOEN )) || (!(irqflags &IRQF_SHARED ) && (irqflags &IRQF_COND_SUSPEND )) || ((irqflags &IRQF_NO_SUSPEND ) && (irqflags &IRQF_COND_SUSPEND )))return -EINVAL ;
@@ -2213,7 +2219,8 @@ int request_nmi(unsigned int irq, irq_handler_t handler, desc =irq_to_desc (irq); -if (!desc ||irq_settings_can_autoenable (desc) || +if (!desc || (irq_settings_can_autoenable (desc) && + !(irqflags &IRQF_NO_AUTOEN )) || !irq_settings_can_request (desc) ||WARN_ON (irq_settings_is_per_cpu_devid (desc)) || !irq_supports_nmi (desc))
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 369/783 iio:imu:adis: Use IRQF_NO_AUTOEN instead of irq request then disable
In reply to Greg Kroah-HartmanFrom: Jonathan Cameron <[email protected]>
[ Upstream commit 30f6a542b7d39b1ba990a28a3891bc03691d8d41 ]
This is a bit involved as the adis library code already has some sanity checking of the flags of the requested irq that we need to ensure is happy to pass through the IRQF_NO_AUTOEN flag untouched.
Using this flag avoids us autoenabling the irq in the adis16460 and adis16475 drivers which cover parts that don't have any means of masking the interrupt on the device end.
Note, compile tested only!
Stable-dep-of: 99c05e4283a1 ("iio: adis: add '__adis_enable_irq()' implementation")
--- drivers/iio/imu/adis16460.c | 4 ++-- drivers/iio/imu/adis16475.c | 5 +++-- drivers/iio/imu/adis_trigger.c | 11 ++++++----- 3 files changed, 11 insertions(+), 9 deletions(-)
drivers/iio/imu/adis16460.c +2 -2
@@ -403,12 +403,12 @@ static int adis16460_probe(struct spi_device *spi)if (ret)return ret; +/* We cannot mask the interrupt, so ensure it isn't auto enabled */ + st->adis.irq_flag |=IRQF_NO_AUTOEN ; ret =devm_adis_setup_buffer_and_trigger (&st->adis, indio_dev,NULL );if (ret)return ret; -adis16460_enable_irq (&st->adis,0 ); - ret =__adis_initial_startup (&st->adis);if (ret)return ret;
drivers/iio/imu/adis16475.c +3 -2
@@ -1196,6 +1196,9 @@ static int adis16475_config_irq_pin(struct adis16475 *st)return -EINVAL ; } +/* We cannot mask the interrupt so ensure it's not enabled at request */ + st->adis.irq_flag |=IRQF_NO_AUTOEN ; + val =ADIS16475_MSG_CTRL_DR_POL (polarity); ret =__adis_update_bits (&st->adis,ADIS16475_REG_MSG_CTRL ,ADIS16475_MSG_CTRL_DR_POL_MASK , val);
@@ -1300,8 +1303,6 @@ static int adis16475_probe(struct spi_device *spi)if (ret)return ret; -adis16475_enable_irq (&st->adis, false); - ret =devm_iio_device_register (&spi->dev, indio_dev);if (ret)return ret;
drivers/iio/imu/adis_trigger.c +6 -5
@@ -36,18 +36,19 @@ static void adis_trigger_setup(struct adis *adis)static int adis_validate_irq_flag (struct adis *adis) { +unsigned long direction = adis->irq_flag &IRQF_TRIGGER_MASK ;/* * Typically this devices have data ready either on the rising edge or * on the falling edge of the data ready pin. This checks enforces that * one of those is set in the drivers... It defaults to -* IRQF_TRIGGER_RISING for backward compatibility wiht devices that +* IRQF_TRIGGER_RISING for backward compatibility with devices that * don't support changing the pin polarity. */ -if (!adis->irq_flag) { - adis->irq_flag =IRQF_TRIGGER_RISING ; +if (direction ==IRQF_TRIGGER_NONE ) { + adis->irq_flag |=IRQF_TRIGGER_RISING ;return 0 ; - }else if (adis->irq_flag !=IRQF_TRIGGER_RISING && - adis->irq_flag !=IRQF_TRIGGER_FALLING ) { + }else if (direction !=IRQF_TRIGGER_RISING && + direction !=IRQF_TRIGGER_FALLING ) {dev_err (&adis->spi->dev,"Invalid IRQ mask: %08lx\n" , adis->irq_flag);return -EINVAL ;
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 370/783 iio: adis: handle devices that cannot unmask the drdy pin
In reply to Greg Kroah-HartmanFrom: Nuno Sá <[email protected]>
[ Upstream commit 31fa357ac809affd9f9a7d0b5d1991951e16beec ]
Some devices can't mask/unmask the data ready pin and in those cases each driver was just calling '{dis}enable_irq()' to control the trigger state. This change, moves that handling into the library by introducing a new boolean in the data structure that tells the library that the device cannot unmask the pin.
On top of controlling the trigger state, we can also use this flag to automatically request the IRQ with 'IRQF_NO_AUTOEN' in case it is set. So far, all users of the library want to start operation with IRQs/DRDY pin disabled so it should be fairly safe to do this inside the library.
Stable-dep-of: 99c05e4283a1 ("iio: adis: add '__adis_enable_irq()' implementation")
--- drivers/iio/imu/adis.c | 15 ++++++++++++++- drivers/iio/imu/adis_trigger.c | 4 ++++ include/linux/iio/imu/adis.h | 2 ++ 3 files changed, 20 insertions(+), 1 deletion(-)
drivers/iio/imu/adis.c +14 -1
@@ -290,6 +290,13 @@ int adis_enable_irq(struct adis *adis, bool enable)if (adis->data->enable_irq) { ret = adis->data->enable_irq (adis, enable); goto out_unlock; + }else if (adis->data->unmasked_drdy) { +if (enable) +enable_irq (adis->spi->irq); +else +disable_irq (adis->spi->irq); + + goto out_unlock; } ret =__adis_read_reg_16 (adis, adis->data->msc_ctrl_reg, &msc);
@@ -434,7 +441,13 @@ int __adis_initial_startup(struct adis *adis)if (ret)return ret; -adis_enable_irq (adis, false); +/* +* don't bother calling this if we can't unmask the IRQ as in this case +* the IRQ is most likely not yet requested and we will request it +* with 'IRQF_NO_AUTOEN' anyways. +*/ +if (!adis->data->unmasked_drdy) +adis_enable_irq (adis, false);if (!adis->data->prod_id_reg)return 0 ;
drivers/iio/imu/adis_trigger.c +4 -0
@@ -37,6 +37,10 @@ static void adis_trigger_setup(struct adis *adis)static int adis_validate_irq_flag (struct adis *adis) {unsigned long direction = adis->irq_flag &IRQF_TRIGGER_MASK ; + +/* We cannot mask the interrupt so ensure it's not enabled at request */ +if (adis->data->unmasked_drdy) + adis->irq_flag |=IRQF_NO_AUTOEN ;/* * Typically this devices have data ready either on the rising edge or * on the falling edge of the data ready pin. This checks enforces that
include/linux/iio/imu/adis.h +2 -0
@@ -49,6 +49,7 @@ struct adis_timeout {* @status_error_mask: Bitmask of errors supported by the device * @timeouts: Chip specific delays * @enable_irq: Hook for ADIS devices that have a special IRQ enable/disable +* @unmasked_drdy: True for devices that cannot mask/unmask the data ready pin * @has_paging: True if ADIS device has paged registers * @burst_reg_cmd: Register command that triggers burst * @burst_len: Burst size in the SPI RX buffer. If @burst_max_len is defined,
@@ -77,6 +78,7 @@ struct adis_data {unsigned int status_error_mask;int (*enable_irq)(struct adis *adis,bool enable); +bool unmasked_drdy;bool has_paging;
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 371/783 iio: adis: stylistic changes
In reply to Greg Kroah-HartmanFrom: Nuno Sá <[email protected]>
[ Upstream commit c39010ea6ba13bdf0003bd353e1d4c663aaac0a8 ]
Minor stylistic changes to address checkptach complains when called with '--strict'.
Stable-dep-of: 99c05e4283a1 ("iio: adis: add '__adis_enable_irq()' implementation")
--- drivers/iio/imu/adis.c | 47 +++++++++++++++++---------------- drivers/iio/imu/adis_buffer.c | 6 ++--- drivers/iio/imu/adis_trigger.c | 3 +-- include/linux/iio/imu/adis.h | 48 ++++++++++++++++++---------------- 4 files changed, 54 insertions(+), 50 deletions(-)
drivers/iio/imu/adis.c +25 -22
@@ -34,8 +34,8 @@* @value: The value to write to device (up to 4 bytes) * @size: The size of the @value (in bytes) */ -int __adis_write_reg (struct adis *adis,unsigned int reg, -unsigned int value,unsigned int size) +int __adis_write_reg (struct adis *adis,unsigned int reg,unsigned int value, +unsigned int size) {unsigned int page = reg /ADIS_PAGE_SIZE ;int ret, i;
@@ -118,7 +118,7 @@ int __adis_write_reg(struct adis *adis, unsigned int reg, ret =spi_sync (adis->spi, &msg);if (ret) {dev_err (&adis->spi->dev,"Failed to write register 0x%02X: %d\n" , - reg, ret); + reg, ret); }else { adis->current_page = page; }
@@ -134,8 +134,8 @@ EXPORT_SYMBOL_GPL(__adis_write_reg);* @val: The value read back from the device * @size: The size of the @val buffer */ -int __adis_read_reg (struct adis *adis,unsigned int reg, -unsigned int *val,unsigned int size) +int __adis_read_reg (struct adis *adis,unsigned int reg,unsigned int *val, +unsigned int size) {unsigned int page = reg /ADIS_PAGE_SIZE ;struct spi_message msg;
@@ -205,12 +205,12 @@ int __adis_read_reg(struct adis *adis, unsigned int reg, ret =spi_sync (adis->spi, &msg);if (ret) {dev_err (&adis->spi->dev,"Failed to read register 0x%02X: %d\n" , - reg, ret); + reg, ret);return ret; - }else { - adis->current_page = page; } + adis->current_page = page; +switch (size) {case 4 : *val =get_unaligned_be32 (adis->rx);
@@ -251,13 +251,13 @@ EXPORT_SYMBOL_GPL(__adis_update_bits_base);#ifdef CONFIG_DEBUG_FS -int adis_debugfs_reg_access (struct iio_dev *indio_dev, -unsigned int reg,unsigned int writeval,unsigned int *readval) +int adis_debugfs_reg_access (struct iio_dev *indio_dev,unsigned int reg, +unsigned int writeval,unsigned int *readval) {struct adis *adis =iio_device_get_drvdata (indio_dev);if (readval) { -uint16_t val16; +u16 val16;int ret; ret =adis_read_reg_16 (adis, reg, &val16);
@@ -265,9 +265,9 @@ int adis_debugfs_reg_access(struct iio_dev *indio_dev, *readval = val16;return ret; - }else { -return adis_write_reg_16 (adis, reg, writeval); } + +return adis_write_reg_16 (adis, reg, writeval); }EXPORT_SYMBOL (adis_debugfs_reg_access);
@@ -283,14 +283,16 @@ EXPORT_SYMBOL(adis_debugfs_reg_access);int adis_enable_irq (struct adis *adis,bool enable) {int ret =0 ; -uint16_t msc; +u16 msc;mutex_lock (&adis->state_lock);if (adis->data->enable_irq) { ret = adis->data->enable_irq (adis, enable); goto out_unlock; - }else if (adis->data->unmasked_drdy) { + } + +if (adis->data->unmasked_drdy) {if (enable)enable_irq (adis->spi->irq);else
@@ -326,7 +328,7 @@ EXPORT_SYMBOL(adis_enable_irq);*/ int __adis_check_status (struct adis *adis) { -uint16_t status; +u16 status;int ret;int i;
@@ -362,7 +364,7 @@ int __adis_reset(struct adis *adis)const struct adis_timeout *timeouts = adis->data->timeouts; ret =__adis_write_reg_8 (adis, adis->data->glob_cmd_reg, -ADIS_GLOB_CMD_SW_RESET ); +ADIS_GLOB_CMD_SW_RESET );if (ret) {dev_err (&adis->spi->dev,"Failed to reset device: %d\n" , ret);return ret;
@@ -418,7 +420,7 @@ int __adis_initial_startup(struct adis *adis) {const struct adis_timeout *timeouts = adis->data->timeouts;struct gpio_desc *gpio; -uint16_t prod_id; +u16 prod_id;int ret;/* check if the device has rst pin low */
@@ -427,7 +429,7 @@ int __adis_initial_startup(struct adis *adis)return PTR_ERR (gpio);if (gpio) { -msleep (10 ); +usleep_range (10 ,12 );/* bring device out of reset */ gpiod_set_value_cansleep (gpio,0 );msleep (timeouts->reset_ms);
@@ -481,7 +483,8 @@ EXPORT_SYMBOL_GPL(__adis_initial_startup);* a error bit in the channels raw value set error_mask to 0. */ int adis_single_conversion (struct iio_dev *indio_dev, -const struct iio_chan_spec *chan,unsigned int error_mask,int *val) +const struct iio_chan_spec *chan, +unsigned int error_mask,int *val) {struct adis *adis =iio_device_get_drvdata (indio_dev);unsigned int uval;
@@ -490,7 +493,7 @@ int adis_single_conversion(struct iio_dev *indio_dev,mutex_lock (&adis->state_lock); ret =__adis_read_reg (adis, chan->address, &uval, - chan->scan_type.storagebits /8 ); + chan->scan_type.storagebits /8 );if (ret) goto err_unlock;
@@ -525,7 +528,7 @@ EXPORT_SYMBOL_GPL(adis_single_conversion);* called. */ int adis_init (struct adis *adis,struct iio_dev *indio_dev, -struct spi_device *spi,const struct adis_data *data) +struct spi_device *spi,const struct adis_data *data) {if (!data || !data->timeouts) {dev_err (&spi->dev,"No config data or timeouts not defined!\n" );
drivers/iio/imu/adis_buffer.c +3 -3
@@ -20,7 +20,7 @@#include <linux/iio/imu/adis.h> static int adis_update_scan_mode_burst (struct iio_dev *indio_dev, -const unsigned long *scan_mask) +const unsigned long *scan_mask) {struct adis *adis =iio_device_get_drvdata (indio_dev);unsigned int burst_length, burst_max_length;
@@ -63,7 +63,7 @@ static int adis_update_scan_mode_burst(struct iio_dev *indio_dev, }int adis_update_scan_mode (struct iio_dev *indio_dev, -const unsigned long *scan_mask) +const unsigned long *scan_mask) {struct adis *adis =iio_device_get_drvdata (indio_dev);const struct iio_chan_spec *chan;
@@ -149,7 +149,7 @@ static irqreturn_t adis_trigger_handler(int irq, void *p) }iio_push_to_buffers_with_timestamp (indio_dev, adis->buffer, - pf->timestamp); + pf->timestamp);iio_trigger_notify_done (indio_dev->trig);
drivers/iio/imu/adis_trigger.c +1 -2
@@ -15,8 +15,7 @@#include <linux/iio/trigger.h> #include <linux/iio/imu/adis.h> -static int adis_data_rdy_trigger_set_state (struct iio_trigger *trig, -bool state) +static int adis_data_rdy_trigger_set_state (struct iio_trigger *trig,bool state) {struct adis *adis =iio_trigger_get_drvdata (trig);
include/linux/iio/imu/adis.h +25 -23
172 lines not on this page · raw message
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 372/783 iio:imu:adis: Move exports into IIO_ADISLIB namespace
In reply to Greg Kroah-HartmanFrom: Jonathan Cameron <[email protected]>
[ Upstream commit 6c9304d6af122f9afea41885ad82ed627e9442a8 ]
In order to avoid unneessary pollution of the global symbol namespace move the common/library functions into a specific namespace and import that into the various specific device drivers that use them.
Stable-dep-of: 99c05e4283a1 ("iio: adis: add '__adis_enable_irq()' implementation")
--- drivers/iio/accel/adis16201.c | 1 + drivers/iio/accel/adis16209.c | 1 + drivers/iio/gyro/adis16136.c | 1 + drivers/iio/gyro/adis16260.c | 1 + drivers/iio/imu/adis.c | 20 ++++++++++---------- drivers/iio/imu/adis16400.c | 1 + drivers/iio/imu/adis16460.c | 1 + drivers/iio/imu/adis16475.c | 1 + drivers/iio/imu/adis16480.c | 1 + drivers/iio/imu/adis_buffer.c | 4 ++-- drivers/iio/imu/adis_trigger.c | 2 +- drivers/staging/iio/accel/adis16203.c | 1 + drivers/staging/iio/accel/adis16240.c | 1 + 13 files changed, 23 insertions(+), 13 deletions(-)
drivers/iio/accel/adis16201.c +1 -0
@@ -304,3 +304,4 @@ MODULE_AUTHOR("Barry Song <[email protected]>");MODULE_DESCRIPTION ("Analog Devices ADIS16201 Dual-Axis Digital Inclinometer and Accelerometer" );MODULE_LICENSE ("GPL v2" );MODULE_ALIAS ("spi:adis16201" ); +MODULE_IMPORT_NS (IIO_ADISLIB );
drivers/iio/accel/adis16209.c +1 -0
@@ -314,3 +314,4 @@ MODULE_AUTHOR("Barry Song <[email protected]>");MODULE_DESCRIPTION ("Analog Devices ADIS16209 Dual-Axis Digital Inclinometer and Accelerometer" );MODULE_LICENSE ("GPL v2" );MODULE_ALIAS ("spi:adis16209" ); +MODULE_IMPORT_NS (IIO_ADISLIB );
drivers/iio/gyro/adis16136.c +1 -0
@@ -599,3 +599,4 @@ module_spi_driver(adis16136_driver);MODULE_AUTHOR ("Lars-Peter Clausen <[email protected]>" );MODULE_DESCRIPTION ("Analog Devices ADIS16133/ADIS16135/ADIS16136 gyroscope driver" );MODULE_LICENSE ("GPL v2" ); +MODULE_IMPORT_NS (IIO_ADISLIB );
drivers/iio/gyro/adis16260.c +1 -0
@@ -438,3 +438,4 @@ module_spi_driver(adis16260_driver);MODULE_AUTHOR ("Barry Song <[email protected]>" );MODULE_DESCRIPTION ("Analog Devices ADIS16260/5 Digital Gyroscope Sensor" );MODULE_LICENSE ("GPL v2" ); +MODULE_IMPORT_NS (IIO_ADISLIB );
drivers/iio/imu/adis.c +10 -10
@@ -125,7 +125,7 @@ int __adis_write_reg(struct adis *adis, unsigned int reg, unsigned int value,return ret; } -EXPORT_SYMBOL_GPL (__adis_write_reg); +EXPORT_SYMBOL_NS_GPL (__adis_write_reg,IIO_ADISLIB );/** * __adis_read_reg() - read N bytes from register (unlocked version)
@@ -222,7 +222,7 @@ int __adis_read_reg(struct adis *adis, unsigned int reg, unsigned int *val,return ret; } -EXPORT_SYMBOL_GPL (__adis_read_reg); +EXPORT_SYMBOL_NS_GPL (__adis_read_reg,IIO_ADISLIB );/** * __adis_update_bits_base() - ADIS Update bits function - Unlocked version * @adis: The adis device
@@ -247,7 +247,7 @@ int __adis_update_bits_base(struct adis *adis, unsigned int reg, const u32 mask,return __adis_write_reg (adis, reg, __val, size); } -EXPORT_SYMBOL_GPL (__adis_update_bits_base); +EXPORT_SYMBOL_NS_GPL (__adis_update_bits_base,IIO_ADISLIB );#ifdef CONFIG_DEBUG_FS
@@ -269,7 +269,7 @@ int adis_debugfs_reg_access(struct iio_dev *indio_dev, unsigned int reg, return adis_write_reg_16(adis, reg, writeval); } -EXPORT_SYMBOL (adis_debugfs_reg_access); +EXPORT_SYMBOL_NS (adis_debugfs_reg_access,IIO_ADISLIB );#endif
@@ -318,7 +318,7 @@ int adis_enable_irq(struct adis *adis, bool enable)mutex_unlock (&adis->state_lock);return ret; } -EXPORT_SYMBOL (adis_enable_irq); +EXPORT_SYMBOL_NS (adis_enable_irq,IIO_ADISLIB );/** * __adis_check_status() - Check the device for error conditions (unlocked)
@@ -350,7 +350,7 @@ int __adis_check_status(struct adis *adis)return -EIO ; } -EXPORT_SYMBOL_GPL (__adis_check_status); +EXPORT_SYMBOL_NS_GPL (__adis_check_status,IIO_ADISLIB );/** * __adis_reset() - Reset the device (unlocked version)
@@ -374,7 +374,7 @@ int __adis_reset(struct adis *adis)return 0 ; } -EXPORT_SYMBOL_GPL (__adis_reset); +EXPORT_SYMBOL_NS_GPL (__adis_reset,IIO_ADIS_LIB );static int adis_self_test (struct adis *adis) {
@@ -465,7 +465,7 @@ int __adis_initial_startup(struct adis *adis)return 0 ; } -EXPORT_SYMBOL_GPL (__adis_initial_startup); +EXPORT_SYMBOL_NS_GPL (__adis_initial_startup,IIO_ADISLIB );/** * adis_single_conversion() - Performs a single sample conversion
@@ -513,7 +513,7 @@ int adis_single_conversion(struct iio_dev *indio_dev,mutex_unlock (&adis->state_lock);return ret; } -EXPORT_SYMBOL_GPL (adis_single_conversion); +EXPORT_SYMBOL_NS_GPL (adis_single_conversion,IIO_ADISLIB );/** * adis_init() - Initialize adis device structure
@@ -550,7 +550,7 @@ int adis_init(struct adis *adis, struct iio_dev *indio_dev,return 0 ; } -EXPORT_SYMBOL_GPL (adis_init); +EXPORT_SYMBOL_NS_GPL (adis_init,IIO_ADISLIB );MODULE_LICENSE ("GPL" );MODULE_AUTHOR ("Lars-Peter Clausen <[email protected]>" );
drivers/iio/imu/adis16400.c +1 -0
@@ -1252,3 +1252,4 @@ module_spi_driver(adis16400_driver);MODULE_AUTHOR ("Manuel Stahl <[email protected]>" );MODULE_DESCRIPTION ("Analog Devices ADIS16400/5 IMU SPI driver" );MODULE_LICENSE ("GPL v2" ); +MODULE_IMPORT_NS (IIO_ADISLIB );
drivers/iio/imu/adis16460.c +1 -0
@@ -447,3 +447,4 @@ module_spi_driver(adis16460_driver);MODULE_AUTHOR ("Dragos Bogdan <[email protected]>" );MODULE_DESCRIPTION ("Analog Devices ADIS16460 IMU driver" );MODULE_LICENSE ("GPL" ); +MODULE_IMPORT_NS (IIO_ADISLIB );
drivers/iio/imu/adis16475.c +1 -0
@@ -1324,3 +1324,4 @@ module_spi_driver(adis16475_driver);MODULE_AUTHOR ("Nuno Sa <[email protected]>" );MODULE_DESCRIPTION ("Analog Devices ADIS16475 IMU driver" );MODULE_LICENSE ("GPL" ); +MODULE_IMPORT_NS (IIO_ADISLIB );
drivers/iio/imu/adis16480.c +1 -0
@@ -1340,3 +1340,4 @@ module_spi_driver(adis16480_driver);MODULE_AUTHOR ("Lars-Peter Clausen <[email protected]>" );MODULE_DESCRIPTION ("Analog Devices ADIS16480 IMU driver" );MODULE_LICENSE ("GPL v2" ); +MODULE_IMPORT_NS (IIO_ADISLIB );
drivers/iio/imu/adis_buffer.c +2 -2
@@ -120,7 +120,7 @@ int adis_update_scan_mode(struct iio_dev *indio_dev,return 0 ; } -EXPORT_SYMBOL_GPL (adis_update_scan_mode); +EXPORT_SYMBOL_NS_GPL (adis_update_scan_mode,IIO_ADISLIB );static irqreturn_t adis_trigger_handler (int irq,void *p) {
@@ -202,5 +202,5 @@ devm_adis_setup_buffer_and_trigger(struct adis *adis, struct iio_dev *indio_dev,return devm_add_action_or_reset (&adis->spi->dev, adis_buffer_cleanup, adis); } -EXPORT_SYMBOL_GPL (devm_adis_setup_buffer_and_trigger); +EXPORT_SYMBOL_NS_GPL (devm_adis_setup_buffer_and_trigger,IIO_ADISLIB );
drivers/iio/imu/adis_trigger.c +1 -1
@@ -92,5 +92,5 @@ int devm_adis_probe_trigger(struct adis *adis, struct iio_dev *indio_dev)return devm_iio_trigger_register (&adis->spi->dev, adis->trig); } -EXPORT_SYMBOL_GPL (devm_adis_probe_trigger); +EXPORT_SYMBOL_NS_GPL (devm_adis_probe_trigger,IIO_ADISLIB );
drivers/staging/iio/accel/adis16203.c +1 -0
@@ -318,3 +318,4 @@ MODULE_AUTHOR("Barry Song <[email protected]>");MODULE_DESCRIPTION ("Analog Devices ADIS16203 Programmable 360 Degrees Inclinometer" );MODULE_LICENSE ("GPL v2" );MODULE_ALIAS ("spi:adis16203" ); +MODULE_IMPORT_NS (IIO_ADISLIB );
drivers/staging/iio/accel/adis16240.c +1 -0
@@ -445,3 +445,4 @@ MODULE_AUTHOR("Barry Song <[email protected]>");MODULE_DESCRIPTION ("Analog Devices Programmable Impact Sensor and Recorder" );MODULE_LICENSE ("GPL v2" );MODULE_ALIAS ("spi:adis16240" ); +MODULE_IMPORT_NS (IIO_ADISLIB );
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 373/783 iio: adis: add __adis_enable_irq() implementation
In reply to Greg Kroah-HartmanFrom: Ramona Bolboaca <[email protected]>
[ Upstream commit 99c05e4283a19a02a256f14100ca4ec3b2da3f62 ]
Add '__adis_enable_irq()' implementation which is the unlocked version of 'adis_enable_irq()'.
Call '__adis_enable_irq()' instead of 'adis_enable_irq()' from '__adis_intial_startup()' to keep the expected unlocked functionality.
This fix is needed to remove a deadlock for all devices which are using 'adis_initial_startup()'. The deadlock occurs because the same mutex is acquired twice, without releasing it.
The mutex is acquired once inside 'adis_initial_startup()', before calling '__adis_initial_startup()', and once inside 'adis_enable_irq()', which is called by '__adis_initial_startup()'. The deadlock is removed by calling '__adis_enable_irq()', instead of 'adis_enable_irq()' from within '__adis_initial_startup()'.
--- drivers/iio/imu/adis.c | 28 ++++++++++------------------ include/linux/iio/imu/adis.h | 13 ++++++++++++- 2 files changed, 22 insertions(+), 19 deletions(-)
drivers/iio/imu/adis.c +10 -18
@@ -274,23 +274,19 @@ EXPORT_SYMBOL_NS(adis_debugfs_reg_access, IIO_ADISLIB);#endif /** -* adis_enable_irq() - Enable or disable data ready IRQ +* __adis_enable_irq() - Enable or disable data ready IRQ (unlocked) * @adis: The adis device * @enable: Whether to enable the IRQ * * Returns 0 on success, negative error code otherwise */ -int adis_enable_irq (struct adis *adis,bool enable) +int __adis_enable_irq (struct adis *adis,bool enable) { -int ret =0 ; +int ret;u16 msc; -mutex_lock (&adis->state_lock); - -if (adis->data->enable_irq) { - ret = adis->data->enable_irq (adis, enable); - goto out_unlock; - } +if (adis->data->enable_irq) +return adis->data->enable_irq (adis, enable);if (adis->data->unmasked_drdy) {if (enable)
@@ -298,12 +294,12 @@ int adis_enable_irq(struct adis *adis, bool enable)else disable_irq (adis->spi->irq); - goto out_unlock; +return 0 ; } ret =__adis_read_reg_16 (adis, adis->data->msc_ctrl_reg, &msc);if (ret) - goto out_unlock; +return ret; msc |=ADIS_MSC_CTRL_DATA_RDY_POL_HIGH ; msc &= ~ADIS_MSC_CTRL_DATA_RDY_DIO2 ;
@@ -312,13 +308,9 @@ int adis_enable_irq(struct adis *adis, bool enable)else msc &= ~ADIS_MSC_CTRL_DATA_RDY_EN ; - ret =__adis_write_reg_16 (adis, adis->data->msc_ctrl_reg, msc); - -out_unlock: -mutex_unlock (&adis->state_lock); -return ret; +return __adis_write_reg_16 (adis, adis->data->msc_ctrl_reg, msc); } -EXPORT_SYMBOL_NS (adis_enable_irq,IIO_ADISLIB ); +EXPORT_SYMBOL_NS (__adis_enable_irq,IIO_ADISLIB );/** * __adis_check_status() - Check the device for error conditions (unlocked)
@@ -449,7 +441,7 @@ int __adis_initial_startup(struct adis *adis)* with 'IRQF_NO_AUTOEN' anyways. */ if (!adis->data->unmasked_drdy) -adis_enable_irq (adis, false); +__adis_enable_irq (adis, false);if (!adis->data->prod_id_reg)return 0 ;
include/linux/iio/imu/adis.h +12 -1
@@ -404,9 +404,20 @@ static inline int adis_update_bits_base(struct adis *adis, unsigned int reg, __adis_update_bits_base(adis, reg, mask, val, 2)); \ }) -int adis_enable_irq (struct adis *adis,bool enable);int __adis_check_status (struct adis *adis);int __adis_initial_startup (struct adis *adis); +int __adis_enable_irq (struct adis *adis,bool enable); + +static inline int adis_enable_irq (struct adis *adis,bool enable) +{ +int ret; + +mutex_lock (&adis->state_lock); + ret =__adis_enable_irq (adis, enable); +mutex_unlock (&adis->state_lock); + +return ret; +}static inline int adis_check_status (struct adis *adis) {
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 374/783 counter: stm32-lptimer-cnt: fix the check on arr and cmp registers update
In reply to Greg Kroah-HartmanFrom: Fabrice Gasnier <[email protected]>
[ Upstream commit fd5ac974fc25feed084c2d1599d0dddb4e0556bc ]
The ARR (auto reload register) and CMP (compare) registers are successively written. The status bits to check the update of these registers are polled together with regmap_read_poll_timeout(). The condition to end the loop may become true, even if one of the register isn't correctly updated.
So ensure both status bits are set before clearing them.
--- drivers/counter/stm32-lptimer-cnt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/counter/stm32-lptimer-cnt.c +1 -1
@@ -69,7 +69,7 @@ static int stm32_lptim_set_enable_state(struct stm32_lptim_cnt *priv,/* ensure CMP & ARR registers are properly written */ ret =regmap_read_poll_timeout (priv->regmap,STM32_LPTIM_ISR , val, - (val &STM32_LPTIM_CMPOK_ARROK ), + (val &STM32_LPTIM_CMPOK_ARROK ) ==STM32_LPTIM_CMPOK_ARROK ,100 ,1000 );if (ret)return ret;
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 375/783 usb: roles: fix of node refcount leak in usb_role_switch_is_parent()
In reply to Greg Kroah-HartmanFrom: Yang Yingliang <[email protected]>
[ Upstream commit 1ab30c610630da5391a373cddb8a065bf4c4bc01 ]
I got the following report while doing device(mt6370-tcpc) load test with CONFIG_OF_UNITTEST and CONFIG_OF_DYNAMIC enabled:
OF: ERROR: memory leak, expected refcount 1 instead of 2, of_node_get()/of_node_put() unbalanced - destroy cset entry:
attach overlay node /i2c/pmic@34
The 'parent' returned by fwnode_get_parent() with refcount incremented. it needs be put after using.
--- drivers/usb/roles/class.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/usb/roles/class.c +4 -1
@@ -106,10 +106,13 @@ usb_role_switch_is_parent(struct fwnode_handle *fwnode)struct fwnode_handle *parent =fwnode_get_parent (fwnode);struct device *dev; -if (!parent || !fwnode_property_present (parent,"usb-role-switch" )) +if (!fwnode_property_present (parent,"usb-role-switch" )) { +fwnode_handle_put (parent);return NULL ; + } dev =class_find_device_by_fwnode (role_class, parent); +fwnode_handle_put (parent);return dev ?to_role_switch (dev) :ERR_PTR (-EPROBE_DEFER ); }
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 376/783 usb: gadget: f_hid: optional SETUP/SET_REPORT mode
In reply to Greg Kroah-HartmanFrom: Maxim Devaev <[email protected]>
[ Upstream commit d7428bc26fc767942c38d74b80299bcd4f01e7cb ]
f_hid provides the OUT Endpoint as only way for receiving reports from the host. SETUP/SET_REPORT method is not supported, and this causes a number of compatibility problems with various host drivers, especially in the case of keyboard emulation using f_hid.
- Some hosts do not support the OUT Endpoint and ignore it, so it becomes impossible for the gadget to receive a report from the host. In the case of a keyboard, the gadget loses the ability to receive the status of the LEDs.
- Some BIOSes/UEFIs can't work with HID devices with the OUT Endpoint at all. This may be due to their bugs or incomplete implementation of the HID standard.
For example, absolutely all Apple UEFIs can't handle the OUT Endpoint if it goes after IN Endpoint in the descriptor and require the reverse order (OUT, IN) which is a violation of the standard. Other hosts either do not initialize gadgets with a descriptor containing the OUT Endpoint completely (like some HP and DELL BIOSes and embedded firmwares like on KVM switches), or initialize them, but will not poll the IN Endpoint.
This patch adds configfs option no_out_endpoint=1 to disable the OUT Endpoint and allows f_hid to receive reports from the host via SETUP/SET_REPORT.
Previously, there was such a feature in f_hid, but it was replaced by the OUT Endpoint [1] in the commit 99c515005857 ("usb: gadget: hidg:
register OUT INT endpoint for SET_REPORT"). So this patch actually returns the removed functionality while making it optional. For backward compatibility reasons, the OUT Endpoint mode remains the default behaviour.
- The OUT Endpoint mode provides the report queue and reduces USB overhead (eliminating SETUP routine) on transmitting a report from the host.
- If the SETUP/SET_REPORT mode is used, there is no report queue, so the userspace will only read last report. For classic HID devices like keyboards this is not a problem, since it's intended to transmit the status of the LEDs and only the last report is important. This mode provides better compatibility with strange and buggy host drivers.
Both modes passed USBCV tests. Checking with the USB protocol analyzer also confirmed that everything is working as it should and the new mode ensures operability in all of the described cases.
Stable-dep-of: 89ff3dfac604 ("usb: gadget: f_hid: fix f_hidg lifetime vs cdev")
--- drivers/usb/gadget/function/f_hid.c | 220 +++++++++++++++++++++++----- drivers/usb/gadget/function/u_hid.h | 1 + 2 files changed, 188 insertions(+), 33 deletions(-)
drivers/usb/gadget/function/f_hid.c +187 -33
@@ -45,12 +45,25 @@ struct f_hidg {unsigned short report_desc_length;char *report_desc;unsigned short report_length; +/* +* use_out_ep - if true, the OUT Endpoint (interrupt out method) +* will be used to receive reports from the host +* using functions with the "intout" suffix. +* Otherwise, the OUT Endpoint will not be configured +* and the SETUP/SET_REPORT method ("ssreport" suffix) +* will be used to receive reports. +*/ +bool use_out_ep;/* recv report */ -struct list_head completed_out_req;spinlock_t read_spinlock;wait_queue_head_t read_queue; +/* recv report - interrupt out only (use_out_ep == 1) */ +struct list_head completed_out_req;unsigned int qlen; +/* recv report - setup set_report only (use_out_ep == 0) */ +char *set_report_buf; +unsigned int set_report_length;/* send report */ spinlock_t write_spinlock;
@@ -79,7 +92,7 @@ static struct usb_interface_descriptor hidg_interface_desc = { .bDescriptorType = USB_DT_INTERFACE,/* .bInterfaceNumber = DYNAMIC */ .bAlternateSetting = 0, - .bNumEndpoints = 2, +/* .bNumEndpoints = DYNAMIC (depends on use_out_ep) */ .bInterfaceClass = USB_CLASS_HID,/* .bInterfaceSubClass = DYNAMIC */ /* .bInterfaceProtocol = DYNAMIC */
@@ -140,7 +153,7 @@ static struct usb_ss_ep_comp_descriptor hidg_ss_out_comp_desc = {/* .wBytesPerInterval = DYNAMIC */ }; -static struct usb_descriptor_header *hidg_ss_descriptors[] = { +static struct usb_descriptor_header *hidg_ss_descriptors_intout[] = { (struct usb_descriptor_header *)&hidg_interface_desc, (struct usb_descriptor_header *)&hidg_desc, (struct usb_descriptor_header *)&hidg_ss_in_ep_desc,
@@ -150,6 +163,14 @@ static struct usb_descriptor_header *hidg_ss_descriptors[] = { NULL, }; +static struct usb_descriptor_header *hidg_ss_descriptors_ssreport[] = { + (struct usb_descriptor_header *)&hidg_interface_desc, + (struct usb_descriptor_header *)&hidg_desc, + (struct usb_descriptor_header *)&hidg_ss_in_ep_desc, + (struct usb_descriptor_header *)&hidg_ss_in_comp_desc, +NULL , +}; +/* High-Speed Support */ static struct usb_endpoint_descriptor hidg_hs_in_ep_desc = {
@@ -176,7 +197,7 @@ static struct usb_endpoint_descriptor hidg_hs_out_ep_desc = {*/ }; -static struct usb_descriptor_header *hidg_hs_descriptors[] = { +static struct usb_descriptor_header *hidg_hs_descriptors_intout[] = { (struct usb_descriptor_header *)&hidg_interface_desc, (struct usb_descriptor_header *)&hidg_desc, (struct usb_descriptor_header *)&hidg_hs_in_ep_desc,
@@ -184,6 +205,13 @@ static struct usb_descriptor_header *hidg_hs_descriptors[] = { NULL, }; +static struct usb_descriptor_header *hidg_hs_descriptors_ssreport[] = { + (struct usb_descriptor_header *)&hidg_interface_desc, + (struct usb_descriptor_header *)&hidg_desc, + (struct usb_descriptor_header *)&hidg_hs_in_ep_desc, +NULL , +}; +/* Full-Speed Support */ static struct usb_endpoint_descriptor hidg_fs_in_ep_desc = {
@@ -210,7 +238,7 @@ static struct usb_endpoint_descriptor hidg_fs_out_ep_desc = {*/ }; -static struct usb_descriptor_header *hidg_fs_descriptors[] = { +static struct usb_descriptor_header *hidg_fs_descriptors_intout[] = { (struct usb_descriptor_header *)&hidg_interface_desc, (struct usb_descriptor_header *)&hidg_desc, (struct usb_descriptor_header *)&hidg_fs_in_ep_desc,
@@ -218,6 +246,13 @@ static struct usb_descriptor_header *hidg_fs_descriptors[] = { NULL, }; +static struct usb_descriptor_header *hidg_fs_descriptors_ssreport[] = { + (struct usb_descriptor_header *)&hidg_interface_desc, + (struct usb_descriptor_header *)&hidg_desc, + (struct usb_descriptor_header *)&hidg_fs_in_ep_desc, +NULL , +}; +/*-------------------------------------------------------------------------*/ /* Strings */
@@ -241,8 +276,8 @@ static struct usb_gadget_strings *ct_func_strings[] = {/*-------------------------------------------------------------------------*/ /* Char Device */ -static ssize_t f_hidg_read (struct file *file,char __user *buffer, -size_t count,loff_t *ptr) +static ssize_t f_hidg_intout_read (struct file *file,char __user *buffer, +size_t count,loff_t *ptr) {struct f_hidg *hidg = file->private_data;struct f_hidg_req_list *list;
@@ -255,15 +290,15 @@ static ssize_t f_hidg_read(struct file *file, char __user *buffer,spin_lock_irqsave (&hidg->read_spinlock, flags); -#define READ_COND (!list_empty(&hidg->completed_out_req)) +#define READ_COND_INTOUT (!list_empty(&hidg->completed_out_req))/* wait for at least one buffer to complete */ -while (!READ_COND ) { +while (!READ_COND_INTOUT ) {spin_unlock_irqrestore (&hidg->read_spinlock, flags);if (file->f_flags &O_NONBLOCK )return -EAGAIN ; -if (wait_event_interruptible (hidg->read_queue,READ_COND )) +if (wait_event_interruptible (hidg->read_queue,READ_COND_INTOUT ))return -ERESTARTSYS ;spin_lock_irqsave (&hidg->read_spinlock, flags);
@@ -313,6 +348,60 @@ static ssize_t f_hidg_read(struct file *file, char __user *buffer,return count; } +#define READ_COND_SSREPORT (hidg->set_report_buf != NULL) + +static ssize_t f_hidg_ssreport_read (struct file *file,char __user *buffer, +size_t count,loff_t *ptr) +{ +struct f_hidg *hidg = file->private_data; +char *tmp_buf =NULL ; +unsigned long flags; + +if (!count) +return 0 ; + +spin_lock_irqsave (&hidg->read_spinlock, flags); + +while (!READ_COND_SSREPORT ) { +spin_unlock_irqrestore (&hidg->read_spinlock, flags); +if (file->f_flags &O_NONBLOCK ) +return -EAGAIN ; + +if (wait_event_interruptible (hidg->read_queue,READ_COND_SSREPORT )) +return -ERESTARTSYS ; + +spin_lock_irqsave (&hidg->read_spinlock, flags); + } + + count = min_t(unsigned int, count, hidg->set_report_length); + tmp_buf = hidg->set_report_buf; + hidg->set_report_buf =NULL ; + +spin_unlock_irqrestore (&hidg->read_spinlock, flags); + +if (tmp_buf !=NULL ) { + count -=copy_to_user (buffer, tmp_buf, count); +kfree (tmp_buf); + }else { + count = -ENOMEM ; + } + +wake_up (&hidg->read_queue); + +return count; +} + +static ssize_t f_hidg_read (struct file *file,char __user *buffer, +size_t count,loff_t *ptr) +{ +struct f_hidg *hidg = file->private_data; + +if (hidg->use_out_ep) +return f_hidg_intout_read (file, buffer, count, ptr); +else +return f_hidg_ssreport_read (file, buffer, count, ptr); +} +static void f_hidg_req_complete (struct usb_ep *ep,struct usb_request *req) {struct f_hidg *hidg = (struct f_hidg *)ep->driver_data;
@@ -433,14 +522,20 @@ static __poll_t f_hidg_poll(struct file *file, poll_table *wait)if (WRITE_COND ) ret |=EPOLLOUT |EPOLLWRNORM ; -if (READ_COND ) - ret |=EPOLLIN |EPOLLRDNORM ; +if (hidg->use_out_ep) { +if (READ_COND_INTOUT ) + ret |=EPOLLIN |EPOLLRDNORM ; + }else { +if (READ_COND_SSREPORT ) + ret |=EPOLLIN |EPOLLRDNORM ; + }return ret; }#undef WRITE_COND -#undef READ_COND +#undef READ_COND_SSREPORT +#undef READ_COND_INTOUTstatic int f_hidg_release (struct inode *inode,struct file *fd) {
@@ -467,7 +562,7 @@ static inline struct usb_request *hidg_alloc_ep_req(struct usb_ep *ep,return alloc_ep_req (ep, length); } -static void hidg_set_report_complete (struct usb_ep *ep,struct usb_request *req) +static void hidg_intout_complete (struct usb_ep *ep,struct usb_request *req) {struct f_hidg *hidg = (struct f_hidg *) req->context;struct usb_composite_dev *cdev = hidg->func.config->cdev;
@@ -502,6 +597,37 @@ static void hidg_set_report_complete(struct usb_ep *ep, struct usb_request *req) } } +static void hidg_ssreport_complete (struct usb_ep *ep,struct usb_request *req) +{ +struct f_hidg *hidg = (struct f_hidg *)req->context; +struct usb_composite_dev *cdev = hidg->func.config->cdev; +char *new_buf =NULL ; +unsigned long flags; + +if (req->status !=0 || req->buf ==NULL || req->actual ==0 ) { +ERROR (cdev, +"%s FAILED: status=%d, buf=%p, actual=%d\n" , + __func__, req->status, req->buf, req->actual); +return ; + } + +spin_lock_irqsave (&hidg->read_spinlock, flags); + + new_buf =krealloc (hidg->set_report_buf, req->actual,GFP_ATOMIC ); +if (new_buf ==NULL ) { +spin_unlock_irqrestore (&hidg->read_spinlock, flags); +return ; + } + hidg->set_report_buf = new_buf; + + hidg->set_report_length = req->actual; +memcpy (hidg->set_report_buf, req->buf, req->actual); + +spin_unlock_irqrestore (&hidg->read_spinlock, flags); + +wake_up (&hidg->read_queue); +} +static int hidg_setup (struct usb_function *f,const struct usb_ctrlrequest *ctrl) {
@@ -549,7 +675,11 @@ static int hidg_setup(struct usb_function *f,case ((USB_DIR_OUT |USB_TYPE_CLASS |USB_RECIP_INTERFACE ) <<8 |HID_REQ_SET_REPORT ):VDBG (cdev,"set_report | wLength=%d\n" , ctrl->wLength); - goto stall; +if (hidg->use_out_ep) + goto stall; + req->complete = hidg_ssreport_complete; + req->context = hidg; + goto respond;break ; case ((USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE) << 8
@@ -637,15 +767,18 @@ static void hidg_disable(struct usb_function *f)unsigned long flags;usb_ep_disable (hidg->in_ep); -usb_ep_disable (hidg->out_ep); -spin_lock_irqsave (&hidg->read_spinlock, flags); -list_for_each_entry_safe (list, next, &hidg->completed_out_req, list) { -free_ep_req (hidg->out_ep, list->req); -list_del (&list->list); -kfree (list); +if (hidg->out_ep) { +usb_ep_disable (hidg->out_ep); + +spin_lock_irqsave (&hidg->read_spinlock, flags); +list_for_each_entry_safe (list, next, &hidg->completed_out_req, list) { +free_ep_req (hidg->out_ep, list->req); +list_del (&list->list); +kfree (list); + } +spin_unlock_irqrestore (&hidg->read_spinlock, flags); } -spin_unlock_irqrestore (&hidg->read_spinlock, flags);spin_lock_irqsave (&hidg->write_spinlock, flags);if (!hidg->write_pending) {
@@ -691,8 +824,7 @@ static int hidg_set_alt(struct usb_function *f, unsigned intf, unsigned alt) } } - -if (hidg->out_ep !=NULL ) { +if (hidg->use_out_ep && hidg->out_ep !=NULL ) {/* restart endpoint */ usb_ep_disable (hidg->out_ep);
@@ -717,7 +849,7 @@ static int hidg_set_alt(struct usb_function *f, unsigned intf, unsigned alt)hidg_alloc_ep_req (hidg->out_ep, hidg->report_length);if (req) { - req->complete = hidg_set_report_complete; + req->complete = hidg_intout_complete; req->context = hidg; status =usb_ep_queue (hidg->out_ep, req,GFP_ATOMIC );
@@ -743,7 +875,8 @@ static int hidg_set_alt(struct usb_function *f, unsigned intf, unsigned alt) }return 0 ; disable_out_ep: -usb_ep_disable (hidg->out_ep); +if (hidg->out_ep) +usb_ep_disable (hidg->out_ep); free_req_in:if (req_in)free_ep_req (hidg->in_ep, req_in);
@@ -795,14 +928,21 @@ static int hidg_bind(struct usb_configuration *c, struct usb_function *f) goto fail; hidg->in_ep = ep; - ep =usb_ep_autoconfig (c->cdev->gadget, &hidg_fs_out_ep_desc); -if (!ep) - goto fail; - hidg->out_ep = ep; + hidg->out_ep =NULL ; +if (hidg->use_out_ep) { + ep =usb_ep_autoconfig (c->cdev->gadget, &hidg_fs_out_ep_desc); +if (!ep) + goto fail; + hidg->out_ep = ep; + } + +/* used only if use_out_ep == 1 */ + hidg->set_report_buf =NULL ;/* set descriptor dynamic values */ hidg_interface_desc.bInterfaceSubClass = hidg->bInterfaceSubClass; hidg_interface_desc.bInterfaceProtocol = hidg->bInterfaceProtocol; + hidg_interface_desc.bNumEndpoints = hidg->use_out_ep ?2 :1 ; hidg->protocol =HID_REPORT_PROTOCOL ; hidg->idle =1 ; hidg_ss_in_ep_desc.wMaxPacketSize =cpu_to_le16 (hidg->report_length);
@@ -833,9 +973,19 @@ static int hidg_bind(struct usb_configuration *c, struct usb_function *f) hidg_ss_out_ep_desc.bEndpointAddress = hidg_fs_out_ep_desc.bEndpointAddress; - status =usb_assign_descriptors (f, hidg_fs_descriptors, - hidg_hs_descriptors, hidg_ss_descriptors, - hidg_ss_descriptors); +if (hidg->use_out_ep) + status =usb_assign_descriptors (f, + hidg_fs_descriptors_intout, + hidg_hs_descriptors_intout, + hidg_ss_descriptors_intout, + hidg_ss_descriptors_intout); +else + status =usb_assign_descriptors (f, + hidg_fs_descriptors_ssreport, + hidg_hs_descriptors_ssreport, + hidg_ss_descriptors_ssreport, + hidg_ss_descriptors_ssreport); +if (status) goto fail;
@@ -950,6 +1100,7 @@ CONFIGFS_ATTR(f_hid_opts_, name)F_HID_OPT (subclass,8 ,255 );F_HID_OPT (protocol,8 ,255 ); +F_HID_OPT (no_out_endpoint,8 ,1 );F_HID_OPT (report_length,16 ,65535 );static ssize_t f_hid_opts_report_desc_show (struct config_item *item,char *page)
@@ -1009,6 +1160,7 @@ CONFIGFS_ATTR_RO(f_hid_opts_, dev);static struct configfs_attribute *hid_attrs[] = { &f_hid_opts_attr_subclass, &f_hid_opts_attr_protocol, + &f_hid_opts_attr_no_out_endpoint, &f_hid_opts_attr_report_length, &f_hid_opts_attr_report_desc, &f_hid_opts_attr_dev,
@@ -1093,6 +1245,7 @@ static void hidg_free(struct usb_function *f) hidg =func_to_hidg (f); opts = container_of(f->fi, struct f_hid_opts, func_inst);kfree (hidg->report_desc); +kfree (hidg->set_report_buf);kfree (hidg);mutex_lock (&opts->lock); --opts->refcnt;
@@ -1139,6 +1292,7 @@ static struct usb_function *hidg_alloc(struct usb_function_instance *fi)return ERR_PTR (-ENOMEM ); } } + hidg->use_out_ep = !opts->no_out_endpoint;mutex_unlock (&opts->lock);
drivers/usb/gadget/function/u_hid.h +1 -0
@@ -20,6 +20,7 @@ struct f_hid_opts {int minor;unsigned char subclass;unsigned char protocol; +unsigned char no_out_endpoint;unsigned short report_length;unsigned short report_desc_length;unsigned char *report_desc;
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 377/783 usb: gadget: f_hid: fix f_hidg lifetime vs cdev
In reply to Greg Kroah-HartmanFrom: John Keeping <[email protected]>
[ Upstream commit 89ff3dfac604614287ad5aad9370c3f984ea3f4b ]
The embedded struct cdev does not have its lifetime correctly tied to the enclosing struct f_hidg, so there is a use-after-free if /dev/hidgN is held open while the gadget is deleted.
This can readily be replicated with libusbgx's example programs (for conciseness - operating directly via configfs is equivalent):
gadget-hid exec 3<> /dev/hidg0 gadget-vid-pid-remove exec 3<&-
Pull the existing device up in to struct f_hidg and make use of the cdev_device_{add,del}() helpers. This changes the lifetime of the device object to match struct f_hidg, but note that it is still added and deleted at the same time.
--- drivers/usb/gadget/function/f_hid.c | 52 ++++++++++++++++------------- 1 file changed, 28 insertions(+), 24 deletions(-)
drivers/usb/gadget/function/f_hid.c +28 -24
@@ -71,7 +71,7 @@ struct f_hidg {wait_queue_head_t write_queue;struct usb_request *req; -int minor; +struct device dev;struct cdev cdev;struct usb_function func;
@@ -84,6 +84,14 @@ static inline struct f_hidg *func_to_hidg(struct usb_function *f) return container_of(f, struct f_hidg, func); } +static void hidg_release (struct device *dev) +{ + struct f_hidg *hidg = container_of(dev, struct f_hidg, dev); + +kfree (hidg->set_report_buf); +kfree (hidg); +} +/*-------------------------------------------------------------------------*/ /* Static descriptors */
@@ -904,9 +912,7 @@ static int hidg_bind(struct usb_configuration *c, struct usb_function *f)struct usb_ep *ep;struct f_hidg *hidg =func_to_hidg (f);struct usb_string *us; -struct device *device;int status; -dev_t dev;/* maybe allocate device-global string IDs, and patch descriptors */ us = usb_gstrings_attach(c->cdev, ct_func_strings,
@@ -999,21 +1005,11 @@ static int hidg_bind(struct usb_configuration *c, struct usb_function *f)/* create char device */ cdev_init (&hidg->cdev, &f_hidg_fops); - dev =MKDEV (major, hidg->minor); - status =cdev_add (&hidg->cdev, dev,1 ); + status =cdev_device_add (&hidg->cdev, &hidg->dev);if (status) goto fail_free_descs; - device =device_create (hidg_class,NULL , dev,NULL , -"%s%d" ,"hidg" , hidg->minor); -if (IS_ERR (device)) { - status =PTR_ERR (device); - goto del; - } -return 0 ; -del: -cdev_del (&hidg->cdev); fail_free_descs:usb_free_all_descriptors (f); fail:
@@ -1244,9 +1240,7 @@ static void hidg_free(struct usb_function *f) hidg =func_to_hidg (f); opts = container_of(f->fi, struct f_hid_opts, func_inst); -kfree (hidg->report_desc); -kfree (hidg->set_report_buf); -kfree (hidg); +put_device (&hidg->dev);mutex_lock (&opts->lock); --opts->refcnt;mutex_unlock (&opts->lock);
@@ -1256,8 +1250,7 @@ static void hidg_unbind(struct usb_configuration *c, struct usb_function *f) {struct f_hidg *hidg =func_to_hidg (f); -device_destroy (hidg_class,MKDEV (major, hidg->minor)); -cdev_del (&hidg->cdev); +cdev_device_del (&hidg->cdev, &hidg->dev);usb_free_all_descriptors (f); }
@@ -1266,6 +1259,7 @@ static struct usb_function *hidg_alloc(struct usb_function_instance *fi) {struct f_hidg *hidg;struct f_hid_opts *opts; +int ret;/* allocate and initialize one new instance */ hidg =kzalloc (sizeof (*hidg),GFP_KERNEL );
@@ -1277,17 +1271,27 @@ static struct usb_function *hidg_alloc(struct usb_function_instance *fi)mutex_lock (&opts->lock); ++opts->refcnt; - hidg->minor = opts->minor; +device_initialize (&hidg->dev); + hidg->dev.release = hidg_release; + hidg->dev.class = hidg_class; + hidg->dev.devt =MKDEV (major, opts->minor); + ret =dev_set_name (&hidg->dev,"hidg%d" , opts->minor); +if (ret) { + --opts->refcnt; +mutex_unlock (&opts->lock); +return ERR_PTR (ret); + } + hidg->bInterfaceSubClass = opts->subclass; hidg->bInterfaceProtocol = opts->protocol; hidg->report_length = opts->report_length; hidg->report_desc_length = opts->report_desc_length;if (opts->report_desc) { - hidg->report_desc =kmemdup (opts->report_desc, - opts->report_desc_length, -GFP_KERNEL ); + hidg->report_desc =devm_kmemdup (&hidg->dev, opts->report_desc, + opts->report_desc_length, +GFP_KERNEL );if (!hidg->report_desc) { -kfree (hidg); +put_device (&hidg->dev);mutex_unlock (&opts->lock);return ERR_PTR (-ENOMEM ); }
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 378/783 usb: gadget: f_hid: fix refcount leak on error path
In reply to Greg Kroah-HartmanFrom: John Keeping <[email protected]>
[ Upstream commit 70a3288a7586526315105c699b687d78cd32559a ]
When failing to allocate report_desc, opts->refcnt has already been incremented so it needs to be decremented to avoid leaving the options structure permanently locked.
--- drivers/usb/gadget/function/f_hid.c | 1 + 1 file changed, 1 insertion(+)
drivers/usb/gadget/function/f_hid.c +1 -0
@@ -1292,6 +1292,7 @@ static struct usb_function *hidg_alloc(struct usb_function_instance *fi) GFP_KERNEL);if (!hidg->report_desc) {put_device (&hidg->dev); + --opts->refcnt;mutex_unlock (&opts->lock);return ERR_PTR (-ENOMEM ); }
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 379/783 drivers: mcb: fix resource leak in mcb_probe()
In reply to Greg Kroah-HartmanFrom: Zhengchao Shao <[email protected]>
[ Upstream commit d7237462561fcd224fa687c56ccb68629f50fc0d ]
When probe hook function failed in mcb_probe(), it doesn't put the device. Compiled test only.
--- drivers/mcb/mcb-core.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/mcb/mcb-core.c +3 -1
@@ -71,8 +71,10 @@ static int mcb_probe(struct device *dev)get_device (dev); ret = mdrv->probe (mdev, found_id); -if (ret) +if (ret) {module_put (carrier_mod); +put_device (dev); + }return ret; }
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 380/783 mcb: mcb-parse: fix error handing in chameleon_parse_gdd()
In reply to Greg Kroah-HartmanFrom: Yang Yingliang <[email protected]>
[ Upstream commit 728ac3389296caf68638628c987aeae6c8851e2d ]
If mcb_device_register() returns error in chameleon_parse_gdd(), the refcount of bus and device name are leaked. Fix this by calling put_device() to give up the reference, so they can be released in mcb_release_dev() and kobject_cleanup().
--- drivers/mcb/mcb-parse.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/mcb/mcb-parse.c +1 -1
@@ -108,7 +108,7 @@ static int chameleon_parse_gdd(struct mcb_bus *bus,return 0 ; err: -mcb_free_dev (mdev); +put_device (&mdev->dev);return ret; }
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 381/783 chardev: fix error handling in cdev_device_add()
In reply to Greg Kroah-HartmanFrom: Yang Yingliang <[email protected]>
[ Upstream commit 11fa7fefe3d8fac7da56bc9aa3dd5fb3081ca797 ]
While doing fault injection test, I got the following report:
------------[ cut here ]------------ kobject: '(null)' (0000000039956980): is not initialized, yet kobject_put() is being called. WARNING: CPU: 3 PID: 6306 at kobject_put+0x23d/0x4e0 CPU: 3 PID: 6306 Comm: 283 Tainted: G W 6.1.0-rc2-00005-g307c1086d7c9 #1253 Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.13.0-1ubuntu1.1 04/01/2014 RIP: 0010:kobject_put+0x23d/0x4e0 Call Trace: <TASK> cdev_device_add+0x15e/0x1b0 __iio_device_register+0x13b4/0x1af0 [industrialio] __devm_iio_device_register+0x22/0x90 [industrialio] max517_probe+0x3d8/0x6b4 [max517] i2c_device_probe+0xa81/0xc00
When device_add() is injected fault and returns error, if dev->devt is not set, cdev_add() is not called, cdev_del() is not needed. Fix this by checking dev->devt in error path.
--- fs/char_dev.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/char_dev.c +1 -1
@@ -547,7 +547,7 @@ int cdev_device_add(struct cdev *cdev, struct device *dev) } rc =device_add (dev); -if (rc) +if (rc && dev->devt)cdev_del (cdev);return rc;
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 382/783 i2c: pxa-pci: fix missing pci_disable_device() on error in ce4100_i2c_probe
In reply to Greg Kroah-HartmanFrom: Hui Tang <[email protected]>
[ Upstream commit d78a167332e1ca8113268ed922c1212fd71b73ad ]
Using pcim_enable_device() to avoid missing pci_disable_device().
--- drivers/i2c/busses/i2c-pxa-pci.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-)
drivers/i2c/busses/i2c-pxa-pci.c +3 -7
@@ -105,7 +105,7 @@ static int ce4100_i2c_probe(struct pci_dev *dev,int i;struct ce4100_devices *sds; - ret =pci_enable_device_mem (dev); + ret =pcim_enable_device (dev);if (ret)return ret;
@@ -114,10 +114,8 @@ static int ce4100_i2c_probe(struct pci_dev *dev,return -EINVAL ; } sds =kzalloc (sizeof (*sds),GFP_KERNEL ); -if (!sds) { - ret = -ENOMEM ; - goto err_mem; - } +if (!sds) +return -ENOMEM ;for (i =0 ; i <ARRAY_SIZE (sds->pdev); i++) { sds->pdev[i] =add_i2c_device (dev, i);
@@ -133,8 +131,6 @@ static int ce4100_i2c_probe(struct pci_dev *dev, err_dev_add:kfree (sds); -err_mem: -pci_disable_device (dev);return ret; }
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 383/783 staging: rtl8192u: Fix use after free in ieee80211_rx()
In reply to Greg Kroah-HartmanFrom: Dan Carpenter <[email protected]>
[ Upstream commit bcc5e2dcf09089b337b76fc1a589f6ff95ca19ac ]
We cannot dereference the "skb" pointer after calling ieee80211_monitor_rx(), because it is a use after free.
--- drivers/staging/rtl8192u/ieee80211/ieee80211_rx.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/staging/rtl8192u/ieee80211/ieee80211_rx.c +3 -1
@@ -954,9 +954,11 @@ int ieee80211_rx(struct ieee80211_device *ieee, struct sk_buff *skb,#endif if (ieee->iw_mode ==IW_MODE_MONITOR ) { +unsigned int len = skb->len; +ieee80211_monitor_rx (ieee, skb, rx_stats); stats->rx_packets++; - stats->rx_bytes += skb->len; + stats->rx_bytes += len;return 1 ; }
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 384/783 staging: rtl8192e: Fix potential use-after-free in rtllib_rx_Monitor()
In reply to Greg Kroah-HartmanFrom: YueHaibing <[email protected]>
[ Upstream commit d30f4436f364b4ad915ca2c09be07cd0f93ceb44 ]
The skb is delivered to netif_rx() in rtllib_monitor_rx(), which may free it, after calling this, dereferencing skb may trigger use-after-free. Found by Smatch.
--- drivers/staging/rtl8192e/rtllib_rx.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/rtl8192e/rtllib_rx.c +1 -1
@@ -1490,9 +1490,9 @@ static int rtllib_rx_Monitor(struct rtllib_device *ieee, struct sk_buff *skb, hdrlen +=4 ; } -rtllib_monitor_rx (ieee, skb, rx_stats, hdrlen); ieee->stats.rx_packets++; ieee->stats.rx_bytes += skb->len; +rtllib_monitor_rx (ieee, skb, rx_stats, hdrlen);return 1 ; }
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 385/783 vme: Fix error not catched in fake_init()
In reply to Greg Kroah-HartmanFrom: Chen Zhongjin <[email protected]>
[ Upstream commit 7bef797d707f1744f71156b21d41e3b8c946631f ]
In fake_init(), __root_device_register() is possible to fail but it's ignored, which can cause unregistering vme_root fail when exit.
general protection fault, probably for non-canonical address 0xdffffc000000008c KASAN: null-ptr-deref in range [0x0000000000000460-0x0000000000000467] RIP: 0010:root_device_unregister+0x26/0x60 Call Trace: <TASK> __x64_sys_delete_module+0x34f/0x540 do_syscall_64+0x38/0x90 entry_SYSCALL_64_after_hwframe+0x63/0xcd
Return error when __root_device_register() fails.
--- drivers/vme/bridges/vme_fake.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/vme/bridges/vme_fake.c +2 -0
@@ -1073,6 +1073,8 @@ static int __init fake_init(void)/* We need a fake parent device */ vme_root =__root_device_register ("vme" ,THIS_MODULE ); +if (IS_ERR (vme_root)) +return PTR_ERR (vme_root);/* If we want to support more than one bridge at some point, we need to * dynamically allocate this so we get one per device.
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 386/783 gpiolib: Get rid of redundant else
In reply to Greg Kroah-HartmanFrom: Andy Shevchenko <[email protected]>
[ Upstream commit 1cef8b5019769d46725932eeace7a383bca97905 ]
In the snippets like the following
if (...) return / goto / break / continue ...; else ...
the 'else' is redundant. Get rid of it. In case of IOCTLs use switch-case pattern that seems the usual in such cases.
While at it, clarify necessity of else in gpiod_direction_output() by attaching else if to the closing curly brace on a previous line.
Stable-dep-of: 533aae7c94db ("gpiolib: cdev: fix NULL-pointer dereferences")
--- drivers/gpio/gpiolib-cdev.c | 66 ++++++++++++++++++++----------------- drivers/gpio/gpiolib.c | 12 +++---- 2 files changed, 40 insertions(+), 38 deletions(-)
drivers/gpio/gpiolib-cdev.c +35 -31
@@ -197,16 +197,15 @@ static long linehandle_ioctl(struct file *file, unsigned int cmd,void __user *ip = (void __user *)arg;struct gpiohandle_data ghd;DECLARE_BITMAP (vals,GPIOHANDLES_MAX ); -int i; +unsigned int i; +int ret; -if (cmd ==GPIOHANDLE_GET_LINE_VALUES_IOCTL ) { -/* NOTE: It's ok to read values of output lines. */ -int ret =gpiod_get_array_value_complex (false, - true, - lh->num_descs, - lh->descs, -NULL , - vals); +switch (cmd) { +case GPIOHANDLE_GET_LINE_VALUES_IOCTL : +/* NOTE: It's okay to read values of output lines */ + ret =gpiod_get_array_value_complex (false, true, + lh->num_descs, lh->descs, +NULL , vals);if (ret)return ret;
@@ -218,7 +217,7 @@ static long linehandle_ioctl(struct file *file, unsigned int cmd,return -EFAULT ;return 0 ; - }else if (cmd ==GPIOHANDLE_SET_LINE_VALUES_IOCTL ) { +case GPIOHANDLE_SET_LINE_VALUES_IOCTL :/* * All line descriptors were created at once with the same * flags so just check if the first one is really output.
@@ -240,10 +239,11 @@ static long linehandle_ioctl(struct file *file, unsigned int cmd, lh->descs,NULL , vals); - }else if (cmd ==GPIOHANDLE_SET_CONFIG_IOCTL ) { +case GPIOHANDLE_SET_CONFIG_IOCTL :return linehandle_set_config (lh, ip); +default : +return -EINVAL ; } -return -EINVAL ; }#ifdef CONFIG_COMPAT
@@ -1165,14 +1165,16 @@ static long linereq_ioctl(struct file *file, unsigned int cmd,struct linereq *lr = file->private_data;void __user *ip = (void __user *)arg; -if (cmd ==GPIO_V2_LINE_GET_VALUES_IOCTL ) +switch (cmd) { +case GPIO_V2_LINE_GET_VALUES_IOCTL :return linereq_get_values (lr, ip); -else if (cmd ==GPIO_V2_LINE_SET_VALUES_IOCTL ) +case GPIO_V2_LINE_SET_VALUES_IOCTL :return linereq_set_values (lr, ip); -else if (cmd ==GPIO_V2_LINE_SET_CONFIG_IOCTL ) +case GPIO_V2_LINE_SET_CONFIG_IOCTL :return linereq_set_config (lr, ip); - -return -EINVAL ; +default : +return -EINVAL ; + } }#ifdef CONFIG_COMPAT
@@ -2095,28 +2097,30 @@ static long gpio_ioctl(struct file *file, unsigned int cmd, unsigned long arg)return -ENODEV ;/* Fill in the struct and pass to userspace */ -if (cmd ==GPIO_GET_CHIPINFO_IOCTL ) { +switch (cmd) { +case GPIO_GET_CHIPINFO_IOCTL :return chipinfo_get (cdev, ip);#ifdef CONFIG_GPIO_CDEV_V1 - }else if (cmd ==GPIO_GET_LINEHANDLE_IOCTL ) { +case GPIO_GET_LINEHANDLE_IOCTL :return linehandle_create (gdev, ip); - }else if (cmd ==GPIO_GET_LINEEVENT_IOCTL ) { +case GPIO_GET_LINEEVENT_IOCTL :return lineevent_create (gdev, ip); - }else if (cmd ==GPIO_GET_LINEINFO_IOCTL || - cmd ==GPIO_GET_LINEINFO_WATCH_IOCTL ) { -return lineinfo_get_v1 (cdev, ip, - cmd ==GPIO_GET_LINEINFO_WATCH_IOCTL ); +case GPIO_GET_LINEINFO_IOCTL : +return lineinfo_get_v1 (cdev, ip, false); +case GPIO_GET_LINEINFO_WATCH_IOCTL : +return lineinfo_get_v1 (cdev, ip, true);#endif /* CONFIG_GPIO_CDEV_V1 */ - }else if (cmd ==GPIO_V2_GET_LINEINFO_IOCTL || - cmd ==GPIO_V2_GET_LINEINFO_WATCH_IOCTL ) { -return lineinfo_get (cdev, ip, - cmd ==GPIO_V2_GET_LINEINFO_WATCH_IOCTL ); - }else if (cmd ==GPIO_V2_GET_LINE_IOCTL ) { +case GPIO_V2_GET_LINEINFO_IOCTL : +return lineinfo_get (cdev, ip, false); +case GPIO_V2_GET_LINEINFO_WATCH_IOCTL : +return lineinfo_get (cdev, ip, true); +case GPIO_V2_GET_LINE_IOCTL :return linereq_create (gdev, ip); - }else if (cmd ==GPIO_GET_LINEINFO_UNWATCH_IOCTL ) { +case GPIO_GET_LINEINFO_UNWATCH_IOCTL :return lineinfo_unwatch (cdev, ip); +default : +return -EINVAL ; } -return -EINVAL ; }#ifdef CONFIG_COMPAT
drivers/gpio/gpiolib.c +5 -7
@@ -186,9 +186,8 @@ static int gpiochip_find_base(int ngpio)/* found a free space? */ if (gdev->base + gdev->ngpio <= base)break ; -else -/* nope, check the space right before the chip */ - base = gdev->base - ngpio; +/* nope, check the space right before the chip */ + base = gdev->base - ngpio; }if (gpio_is_valid (base)) {
@@ -2481,8 +2480,7 @@ int gpiod_direction_output(struct gpio_desc *desc, int value) ret =gpiod_direction_input (desc); goto set_output_flag; } - } -else if (test_bit (FLAG_OPEN_SOURCE , &desc->flags)) { + }else if (test_bit (FLAG_OPEN_SOURCE , &desc->flags)) { ret =gpio_set_config (desc,PIN_CONFIG_DRIVE_OPEN_SOURCE );if (!ret) goto set_output_value;
@@ -2656,9 +2654,9 @@ static int gpiod_get_raw_value_commit(const struct gpio_desc *desc)static int gpio_chip_get_multiple (struct gpio_chip *gc,unsigned long *mask,unsigned long *bits) { -if (gc->get_multiple) { +if (gc->get_multiple)return gc->get_multiple (gc, mask, bits); - }else if (gc->get) { +if (gc->get) {int i, value;for_each_set_bit (i, mask, gc->ngpio) {
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 387/783 gpiolib: cdev: fix NULL-pointer dereferences
In reply to Greg Kroah-HartmanFrom: Bartosz Golaszewski <[email protected]>
[ Upstream commit 533aae7c94dbc2b14301cfd68ae7e0e90f0c8438 ]
There are several places where we can crash the kernel by requesting lines, unbinding the GPIO device, then calling any of the system calls relevant to the GPIO character device's annonymous file descriptors:ioctl(), read(), poll().
While I observed it with the GPIO simulator, it will also happen for any of the GPIO devices that can be hot-unplugged - for instance any HID GPIO expander (e.g. CP2112).
This affects both v1 and v2 uAPI.
This fixes it partially by checking if gdev->chip is not NULL but it doesn't entirely remedy the situation as we still have a race condition in which another thread can remove the device after the check.
--- drivers/gpio/gpiolib-cdev.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+)
drivers/gpio/gpiolib-cdev.c +27 -0
@@ -200,6 +200,9 @@ static long linehandle_ioctl(struct file *file, unsigned int cmd,unsigned int i;int ret; +if (!lh->gdev->chip) +return -ENODEV ; +switch (cmd) {case GPIOHANDLE_GET_LINE_VALUES_IOCTL :/* NOTE: It's okay to read values of output lines */
@@ -1165,6 +1168,9 @@ static long linereq_ioctl(struct file *file, unsigned int cmd,struct linereq *lr = file->private_data;void __user *ip = (void __user *)arg; +if (!lr->gdev->chip) +return -ENODEV ; +switch (cmd) {case GPIO_V2_LINE_GET_VALUES_IOCTL :return linereq_get_values (lr, ip);
@@ -1191,6 +1197,9 @@ static __poll_t linereq_poll(struct file *file,struct linereq *lr = file->private_data;__poll_t events =0 ; +if (!lr->gdev->chip) +return EPOLLHUP |EPOLLERR ; +poll_wait (file, &lr->wait, wait); if (!kfifo_is_empty_spinlocked_noirqsave(&lr->events,
@@ -1210,6 +1219,9 @@ static ssize_t linereq_read(struct file *file,ssize_t bytes_read =0 ;int ret; +if (!lr->gdev->chip) +return -ENODEV ; +if (count <sizeof (le))return -EINVAL ;
@@ -1475,6 +1487,9 @@ static __poll_t lineevent_poll(struct file *file,struct lineevent_state *le = file->private_data;__poll_t events =0 ; +if (!le->gdev->chip) +return EPOLLHUP |EPOLLERR ; +poll_wait (file, &le->wait, wait);if (!kfifo_is_empty_spinlocked_noirqsave (&le->events, &le->wait.lock))
@@ -1510,6 +1525,9 @@ static ssize_t lineevent_read(struct file *file,ssize_t ge_size;int ret; +if (!le->gdev->chip) +return -ENODEV ; +/* * When compatible system call is being used the struct gpioevent_data, * in case of at least ia32, has different size due to the alignment
@@ -1588,6 +1606,9 @@ static long lineevent_ioctl(struct file *file, unsigned int cmd,void __user *ip = (void __user *)arg;struct gpiohandle_data ghd; +if (!le->gdev->chip) +return -ENODEV ; +/* * We can get the value for an event line but not set it, * because it is input by definition.
@@ -2168,6 +2189,9 @@ static __poll_t lineinfo_watch_poll(struct file *file,struct gpio_chardev_data *cdev = file->private_data;__poll_t events =0 ; +if (!cdev->gdev->chip) +return EPOLLHUP |EPOLLERR ; +poll_wait (file, &cdev->wait, pollt); if (!kfifo_is_empty_spinlocked_noirqsave(&cdev->events,
@@ -2186,6 +2210,9 @@ static ssize_t lineinfo_watch_read(struct file *file, char __user *buf,int ret;size_t event_size; +if (!cdev->gdev->chip) +return -ENODEV ; +#ifndef CONFIG_GPIO_CDEV_V1 event_size =sizeof (struct gpio_v2_line_info_changed );if (count < event_size)
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 388/783 i2c: mux: reg: check return value after calling platform_get_resource()
In reply to Greg Kroah-HartmanFrom: Yang Yingliang <[email protected]>
[ Upstream commit 2d47b79d2bd39cc6369eccf94a06568d84c906ae ]
It will cause null-ptr-deref in resource_size(), if platform_get_resource() returns NULL, move calling resource_size() after devm_ioremap_resource() that will check 'res' to avoid null-ptr-deref.
And use devm_platform_get_and_ioremap_resource() to simplify code.
--- drivers/i2c/muxes/i2c-mux-reg.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/i2c/muxes/i2c-mux-reg.c +2 -3
@@ -183,13 +183,12 @@ static int i2c_mux_reg_probe(struct platform_device *pdev)if (!mux->data.reg) {dev_info (&pdev->dev,"Register not set, using platform resource\n" ); - res =platform_get_resource (pdev,IORESOURCE_MEM ,0 ); - mux->data.reg_size =resource_size (res); - mux->data.reg =devm_ioremap_resource (&pdev->dev, res); + mux->data.reg =devm_platform_get_and_ioremap_resource (pdev,0 , &res);if (IS_ERR (mux->data.reg)) { ret =PTR_ERR (mux->data.reg); goto err_put_parent; } + mux->data.reg_size =resource_size (res); } if (mux->data.reg_size != 4 && mux->data.reg_size != 2 &&
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 389/783 i2c: ismt: Fix an out-of-bounds bug in ismt_access()
In reply to Greg Kroah-HartmanFrom: Zheyu Ma <[email protected]>
[ Upstream commit 39244cc754829bf707dccd12e2ce37510f5b1f8d ]
When the driver does not check the data from the user, the variable 'data->block[0]' may be very large to cause an out-of-bounds bug.
The following log can reveal it:
[ 33.995542] i2c i2c-1: ioctl, cmd=0x720, arg=0x7ffcb3dc3a20 [ 33.995978] ismt_smbus 0000:00:05.0: I2C_SMBUS_BLOCK_DATA: WRITE [ 33.996475] ================================================================== [ 33.996995] BUG: KASAN: out-of-bounds in ismt_access.cold+0x374/0x214b [ 33.997473] Read of size 18446744073709551615 at addr ffff88810efcfdb1 by task ismt_poc/485 [ 33.999450] Call Trace: [ 34.001849] memcpy+0x20/0x60 [ 34.002077] ismt_access.cold+0x374/0x214b [ 34.003382] __i2c_smbus_xfer+0x44f/0xfb0 [ 34.004007] i2c_smbus_xfer+0x10a/0x390 [ 34.004291] i2cdev_ioctl_smbus+0x2c8/0x710 [ 34.005196] i2cdev_ioctl+0x5ec/0x74c
Fix this bug by checking the size of 'data->block[0]' first.
--- drivers/i2c/busses/i2c-ismt.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/i2c/busses/i2c-ismt.c +3 -0
@@ -507,6 +507,9 @@ static int ismt_access(struct i2c_adapter *adap, u16 addr,if (read_write ==I2C_SMBUS_WRITE ) {/* Block Write */ dev_dbg (dev,"I2C_SMBUS_BLOCK_DATA: WRITE\n" ); +if (data->block[0 ] <1 || data->block[0 ] >I2C_SMBUS_BLOCK_MAX ) +return -EINVAL ; + dma_size = data->block[0 ] +1 ; dma_direction =DMA_TO_DEVICE ; desc->wr_len_cmd = dma_size;
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 390/783 usb: storage: Add check for kcalloc
In reply to Greg Kroah-HartmanFrom: Jiasheng Jiang <[email protected]>
[ Upstream commit c35ca10f53c51eeb610d3f8fbc6dd6d511b58a58 ]
As kcalloc may return NULL pointer, the return value should be checked and return error if fails as same as the ones in alauda_read_map.
--- drivers/usb/storage/alauda.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/usb/storage/alauda.c +2 -0
@@ -438,6 +438,8 @@ static int alauda_init_media(struct us_data *us) + MEDIA_INFO(us).blockshift + MEDIA_INFO(us).pageshift);MEDIA_INFO (us).pba_to_lba =kcalloc (num_zones,sizeof (u16 *),GFP_NOIO );MEDIA_INFO (us).lba_to_pba =kcalloc (num_zones,sizeof (u16 *),GFP_NOIO ); +if (MEDIA_INFO (us).pba_to_lba ==NULL ||MEDIA_INFO (us).lba_to_pba ==NULL ) +return USB_STOR_TRANSPORT_ERROR ;if (alauda_reset_media (us) !=USB_STOR_XFER_GOOD )return USB_STOR_TRANSPORT_ERROR ;
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 391/783 tracing/hist: Fix issue of losting command info in error_log
In reply to Greg Kroah-HartmanFrom: Zheng Yejian <[email protected]>
[ Upstream commit 608c6ed3337850c767ab0dd6c583477922233e29 ]
When input some constructed invalid 'trigger' command, command info in 'error_log' are lost [1].
The root cause is that there is a path that event_hist_trigger_parse() is recursely called once and 'last_cmd' which save origin command is cleared, then later calling of hist_err() will no longer record origin command info:
event_hist_trigger_parse() {
last_cmd_set() // <1> 'last_cmd' save origin command here at first
create_actions() {
onmatch_create() {
action_create() {
trace_action_create() {
trace_action_create_field_var() {
create_field_var_hist() {
event_hist_trigger_parse() { // <2> recursely called once
hist_err_clear() // <3> 'last_cmd' is cleared here
}
hist_err() // <4> No longer find origin command!!!Since 'glob' is empty string while running into the recurse call, we can trickly check it and bypass the call of hist_err_clear() to solve it.
[1]
# cd /sys/kernel/tracing
# echo "my_synth_event int v1; int v2; int v3;" >> synthetic_events
# echo 'hist:keys=pid' >> events/sched/sched_waking/trigger
# echo "hist:keys=next_pid:onmatch(sched.sched_waking).my_synth_event(\
pid,pid1)" >> events/sched/sched_switch/trigger
# cat error_log
[ 8.405018] hist:sched:sched_switch: error: Couldn't find synthetic event
Command:
hist:keys=next_pid:onmatch(sched.sched_waking).my_synth_event(pid,pid1)
^
[ 8.816902] hist:sched:sched_switch: error: Couldn't find field
Command:
hist:keys=next_pid:onmatch(sched.sched_waking).my_synth_event(pid,pid1)
^
[ 8.816902] hist:sched:sched_switch: error: Couldn't parse field variable
Command:
hist:keys=next_pid:onmatch(sched.sched_waking).my_synth_event(pid,pid1)
^
[ 8.999880] : error: Couldn't find field
Command:
^
[ 8.999880] : error: Couldn't parse field variable
Command:
^
[ 8.999880] : error: Couldn't find field
Command:
^
[ 8.999880] : error: Couldn't create histogram for field
Command:
^--- kernel/trace/trace_events_hist.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/trace/trace_events_hist.c +1 -1
@@ -5827,7 +5827,7 @@ static int event_hist_trigger_func(struct event_command *cmd_ops,/* Just return zero, not the number of registered triggers */ ret =0 ; out: -if (ret ==0 ) +if (ret ==0 && glob[0 ])hist_err_clear ();return ret;
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 392/783 samples: vfio-mdev: Fix missing pci_disable_device() in mdpy_fb_probe()
In reply to Greg Kroah-HartmanFrom: Shang XiaoJing <[email protected]>
[ Upstream commit d1f0f50fbbbbca1e3e8157e51934613bf88f6d44 ]
Add missing pci_disable_device() in fail path of mdpy_fb_probe(). Besides, fix missing release functions in mdpy_fb_remove().
--- samples/vfio-mdev/mdpy-fb.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
samples/vfio-mdev/mdpy-fb.c +7 -1
@@ -109,7 +109,7 @@ static int mdpy_fb_probe(struct pci_dev *pdev, ret =pci_request_regions (pdev,"mdpy-fb" );if (ret <0 ) -return ret; + goto err_disable_dev;pci_read_config_dword (pdev,MDPY_FORMAT_OFFSET , &format);pci_read_config_dword (pdev,MDPY_WIDTH_OFFSET , &width);
@@ -191,6 +191,9 @@ static int mdpy_fb_probe(struct pci_dev *pdev, err_release_regions:pci_release_regions (pdev); +err_disable_dev: +pci_disable_device (pdev); +return ret; }
@@ -199,7 +202,10 @@ static void mdpy_fb_remove(struct pci_dev *pdev)struct fb_info *info =pci_get_drvdata (pdev);unregister_framebuffer (info); +iounmap (info->screen_base);framebuffer_release (info); +pci_release_regions (pdev); +pci_disable_device (pdev); }static struct pci_device_id mdpy_fb_pci_table[] = {
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 393/783 thermal/drivers/imx8mm_thermal: Validate temperature range
In reply to Greg Kroah-HartmanFrom: Marcus Folkesson <[email protected]>
[ Upstream commit d37edc7370273306d8747097fafa62436c1cfe16 ]
Check against the upper temperature limit (125 degrees C) before consider the temperature valid.
--- drivers/thermal/imx8mm_thermal.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
drivers/thermal/imx8mm_thermal.c +7 -1
@@ -65,8 +65,14 @@ static int imx8mm_tmu_get_temp(void *data, int *temp)u32 val; val =readl_relaxed (tmu->base +TRITSR ) &TRITSR_TEMP0_VAL_MASK ; + +/* +* Do not validate against the V bit (bit 31) due to errata +* ERR051272: TMU: Bit 31 of registers TMU_TSCR/TMU_TRITSR/TMU_TRATSR invalid +*/ + *temp = val *1000 ; -if (*temp <VER1_TEMP_LOW_LIMIT ) +if (*temp <VER1_TEMP_LOW_LIMIT || *temp >VER2_TEMP_HIGH_LIMIT )return -EAGAIN ;return 0 ;
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 394/783 fbdev: ssd1307fb: Drop optional dependency
In reply to Greg Kroah-HartmanFrom: Andy Shevchenko <[email protected]>
[ Upstream commit 025e3b507a3a8e1ee96a3112bb67495c77d6cdb6 ]
Only a single out of three devices need a PWM, so from driver it's optional. Moreover it's a single driver in the entire kernel that currently selects PWM. Unfortunately this selection is a root cause of the circular dependencies when we want to enable optional PWM for some other drivers that select GPIOLIB.
--- drivers/video/fbdev/Kconfig | 1 - 1 file changed, 1 deletion(-)
drivers/video/fbdev/Kconfig +0 -1
@@ -2216,7 +2216,6 @@ config FB_SSD1307 select FB_SYS_COPYAREA select FB_SYS_IMAGEBLIT select FB_DEFERRED_IO - select PWM select FB_BACKLIGHT help This driver implements support for the Solomon SSD1307
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 395/783 fbdev: pm2fb: fix missing pci_disable_device()
In reply to Greg Kroah-HartmanFrom: Yang Yingliang <[email protected]>
[ Upstream commit ed359a464846b48f76ea6cc5cd8257e545ac97f4 ]
Add missing pci_disable_device() in error path of probe() and remove() path.
--- drivers/video/fbdev/pm2fb.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)
drivers/video/fbdev/pm2fb.c +7 -2
@@ -1529,8 +1529,10 @@ static int pm2fb_probe(struct pci_dev *pdev, const struct pci_device_id *id) } info =framebuffer_alloc (sizeof (struct pm2fb_par ), &pdev->dev); -if (!info) -return -ENOMEM ; +if (!info) { + err = -ENOMEM ; + goto err_exit_disable; + } default_par = info->par;switch (pdev->device) {
@@ -1711,6 +1713,8 @@ static int pm2fb_probe(struct pci_dev *pdev, const struct pci_device_id *id)release_mem_region (pm2fb_fix.mmio_start, pm2fb_fix.mmio_len); err_exit_neither:framebuffer_release (info); + err_exit_disable: +pci_disable_device (pdev);return retval; }
@@ -1737,6 +1741,7 @@ static void pm2fb_remove(struct pci_dev *pdev)fb_dealloc_cmap (&info->cmap);kfree (info->pixmap.addr);framebuffer_release (info); +pci_disable_device (pdev); }static const struct pci_device_id pm2fb_id_table[] = {
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 396/783 fbdev: via: Fix error in via_core_init()
In reply to Greg Kroah-HartmanFrom: Shang XiaoJing <[email protected]>
[ Upstream commit 5886b130de953cfb8826f7771ec8640a79934a7f ]
via_core_init() won't exit the driver when pci_register_driver() failed. Exit the viafb-i2c and the viafb-gpio in failed path to prevent error.
VIA Graphics Integration Chipset framebuffer 2.4 initializing
Error: Driver 'viafb-i2c' is already registered, aborting...
Error: Driver 'viafb-gpio' is already registered, aborting...
--- drivers/video/fbdev/via/via-core.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)
drivers/video/fbdev/via/via-core.c +8 -1
@@ -725,7 +725,14 @@ static int __init via_core_init(void)return ret;viafb_i2c_init ();viafb_gpio_init (); -return pci_register_driver (&via_driver); + ret =pci_register_driver (&via_driver); +if (ret) { +viafb_gpio_exit (); +viafb_i2c_exit (); +return ret; + } + +return 0 ; } static void __exit via_core_exit(void)
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 397/783 fbdev: vermilion: decrease reference count in error path
In reply to Greg Kroah-HartmanFrom: Xiongfeng Wang <[email protected]>
[ Upstream commit 001f2cdb952a9566c77fb4b5470cc361db5601bb ]
pci_get_device() will increase the reference count for the returned pci_dev. For the error path, we need to use pci_dev_put() to decrease the reference count.
--- drivers/video/fbdev/vermilion/vermilion.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/video/fbdev/vermilion/vermilion.c +3 -1
@@ -277,8 +277,10 @@ static int vmlfb_get_gpu(struct vml_par *par)mutex_unlock (&vml_mutex); -if (pci_enable_device (par->gpu) <0 ) +if (pci_enable_device (par->gpu) <0 ) { +pci_dev_put (par->gpu);return -ENODEV ; + }return 0 ; }
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 398/783 fbdev: uvesafb: Fixes an error handling path in uvesafb_probe()
In reply to Greg Kroah-HartmanFrom: Christophe JAILLET <[email protected]>
[ Upstream commit a94371040712031ba129c7e9d8ff04a06a2f8207 ]
If an error occurs after a successful uvesafb_init_mtrr() call, it must be undone by a corresponding arch_phys_wc_del() call, as already done in the remove function.
This has been added in the remove function in commit 63e28a7a5ffc ("uvesafb: Clean up MTRR code")
--- drivers/video/fbdev/uvesafb.c | 1 + 1 file changed, 1 insertion(+)
drivers/video/fbdev/uvesafb.c +1 -0
@@ -1756,6 +1756,7 @@ static int uvesafb_probe(struct platform_device *dev) out_unmap:iounmap (info->screen_base); out_mem: +arch_phys_wc_del (par->mtrr_handle);release_mem_region (info->fix.smem_start, info->fix.smem_len); out_reg:release_region (0x3c0 ,32 );
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 399/783 HSI: omap_ssi_core: fix unbalanced pm_runtime_disable()
In reply to Greg Kroah-HartmanFrom: Yang Yingliang <[email protected]>
[ Upstream commit f5181c35ed7ba0ceb6e42872aad1334d994b0175 ]
In error label 'out1' path in ssi_probe(), the pm_runtime_enable() has not been called yet, so pm_runtime_disable() is not needed.
--- drivers/hsi/controllers/omap_ssi_core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/hsi/controllers/omap_ssi_core.c +1 -1
@@ -536,9 +536,9 @@ static int ssi_probe(struct platform_device *pd)device_for_each_child (&pd->dev,NULL , ssi_remove_ports); out2:ssi_remove_controller (ssi); +pm_runtime_disable (&pd->dev); out1:platform_set_drvdata (pd,NULL ); -pm_runtime_disable (&pd->dev);return err; }
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 400/783 HSI: omap_ssi_core: fix possible memory leak in ssi_probe()
In reply to Greg Kroah-HartmanFrom: Yang Yingliang <[email protected]>
[ Upstream commit 1aff514e1d2bd47854dbbdf867970b9d463d4c57 ]
If ssi_add_controller() returns error, it should call hsi_put_controller() to give up the reference that was set in hsi_alloc_controller(), so that it can call hsi_controller_release() to free controller and ports that allocated in hsi_alloc_controller().
--- drivers/hsi/controllers/omap_ssi_core.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/hsi/controllers/omap_ssi_core.c +3 -1
@@ -502,8 +502,10 @@ static int ssi_probe(struct platform_device *pd)platform_set_drvdata (pd, ssi); err =ssi_add_controller (ssi, pd); -if (err <0 ) +if (err <0 ) { +hsi_put_controller (ssi); goto out1; + }pm_runtime_enable (&pd->dev);
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 401/783 power: supply: fix residue sysfs file in error handle route of __power_supply_register()
In reply to Greg Kroah-HartmanFrom: Zeng Heng <[email protected]>
[ Upstream commit 5b79480ce1978864ac3f06f2134dfa3b6691fe74 ]
If device_add() succeeds, we should call device_del() when want to get rid of it, so move it into proper jump symbol.
Otherwise, when __power_supply_register() returns fail and goto wakeup_init_failed to exit, there is still residue device file in sysfs. When attempt to probe device again, sysfs would complain as below:
sysfs: cannot create duplicate filename '/devices/platform/i2c/i2c-0/0-001c/power_supply/adp5061'
Call Trace: dump_stack_lvl+0x68/0x85 sysfs_warn_dup.cold+0x1c/0x29 sysfs_create_dir_ns+0x1b1/0x1d0 kobject_add_internal+0x143/0x390 kobject_add+0x108/0x170
--- drivers/power/supply/power_supply_core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/power/supply/power_supply_core.c +1 -1
@@ -1201,8 +1201,8 @@ __power_supply_register(struct device *parent, register_cooler_failed:psy_unregister_thermal (psy); register_thermal_failed: -device_del (dev); wakeup_init_failed: +device_del (dev); device_add_failed: check_supplies_failed: dev_set_name_failed:
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 402/783 perf trace: Return error if a system call doesnt exist
In reply to Greg Kroah-HartmanFrom: Leo Yan <[email protected]>
[ Upstream commit d4223e1776c30b2ce8d0e6eaadcbf696e60fca3c ]
When a system call is not detected, the reason is either because the system call ID is out of scope or failure to find the corresponding path in the sysfs, trace__read_syscall_info() returns zero. Finally, without returning an error value it introduces confusion for the caller.
This patch lets the function trace__read_syscall_info() to return -EEXIST when a system call doesn't exist.
--- tools/perf/builtin-trace.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
tools/perf/builtin-trace.c +2 -2
@@ -1774,11 +1774,11 @@ static int trace__read_syscall_info(struct trace *trace, int id)#endif sc = trace->syscalls.table + id;if (sc->nonexistent) -return 0 ; +return -EEXIST ;if (name ==NULL ) { sc->nonexistent = true; -return 0 ; +return -EEXIST ; } sc->name = name;
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 403/783 perf trace: Use macro RAW_SYSCALL_ARGS_NUM to replace number
In reply to Greg Kroah-HartmanFrom: Leo Yan <[email protected]>
[ Upstream commit eadcab4c7a66e1df03d32da0db55d89fd9343fcc ]
This patch defines a macro RAW_SYSCALL_ARGS_NUM to replace the open coded number '6'.
Stable-dep-of: 03e9a5d8eb55 ("perf trace: Handle failure when trace point folder is missed")
--- tools/perf/builtin-trace.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-)
tools/perf/builtin-trace.c +7 -4
@@ -87,6 +87,8 @@# define F_LINUX_SPECIFIC_BASE 1024#endif +#define RAW_SYSCALL_ARGS_NUM 6 +/* * strtoul: Go from a string to a value, i.e. for msr: MSR_FS_BASE to 0xc0000100 */
@@ -107,7 +109,7 @@ struct syscall_fmt {const char *sys_enter, *sys_exit; } bpf_prog_name; -struct syscall_arg_fmt arg[6 ]; +struct syscall_arg_fmt arg[RAW_SYSCALL_ARGS_NUM ];u8 nr_args;bool errpid;bool timeout;
@@ -1216,7 +1218,7 @@ struct syscall {*/ struct bpf_map_syscall_entry {bool enabled; -u16 string_args_len[6 ]; +u16 string_args_len[RAW_SYSCALL_ARGS_NUM ]; };/*
@@ -1641,7 +1643,7 @@ static int syscall__alloc_arg_fmts(struct syscall *sc, int nr_args) {int idx; -if (nr_args ==6 && sc->fmt && sc->fmt->nr_args !=0 ) +if (nr_args ==RAW_SYSCALL_ARGS_NUM && sc->fmt && sc->fmt->nr_args !=0 ) nr_args = sc->fmt->nr_args; sc->arg_fmt =calloc (nr_args,sizeof (*sc->arg_fmt));
@@ -1792,7 +1794,8 @@ static int trace__read_syscall_info(struct trace *trace, int id) sc->tp_format =trace_event__tp_format ("syscalls" , tp_name); } -if (syscall__alloc_arg_fmts (sc,IS_ERR (sc->tp_format) ?6 : sc->tp_format->format.nr_fields)) +if (syscall__alloc_arg_fmts (sc,IS_ERR (sc->tp_format) ? +RAW_SYSCALL_ARGS_NUM : sc->tp_format->format.nr_fields))return -ENOMEM ;if (IS_ERR (sc->tp_format))
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 404/783 perf trace: Handle failure when trace point folder is missed
In reply to Greg Kroah-HartmanFrom: Leo Yan <[email protected]>
[ Upstream commit 03e9a5d8eb552a1bf692a9c8a5ecd50f4e428006 ]
On Arm64 a case is perf tools fails to find the corresponding trace point folder for system calls listed in the table 'syscalltbl_arm64', e.g. the generated system call table contains "lookup_dcookie" but we cannot find out the matched trace point folder for it.
We need to figure out if there have any issue for the generated system call table, on the other hand, we need to handle the case when trace point folder is missed under sysfs, this patch sets the flag syscall::nonexistent as true and returns the error from trace__read_syscall_info().
Another problem is for trace__syscall_info(), it returns two different values if a system call doesn't exist: at the first time calling trace__syscall_info() it returns NULL when the system call doesn't exist, later if call trace__syscall_info() again for the same missed system call, it returns pointer of syscall. trace__syscall_info() checks the condition 'syscalls.table[id].name == NULL', but the name will be assigned in the first invoking even the system call is not found.
So checking system call's name in trace__syscall_info() is not the right thing to do, this patch simply checks flag syscall::nonexistent to make decision if a system call exists or not, finally trace__syscall_info() returns the consistent result (NULL) if a system call doesn't existed.
--- tools/perf/builtin-trace.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-)
tools/perf/builtin-trace.c +10 -7
@@ -1794,13 +1794,19 @@ static int trace__read_syscall_info(struct trace *trace, int id) sc->tp_format =trace_event__tp_format ("syscalls" , tp_name); } +/* +* Fails to read trace point format via sysfs node, so the trace point +* doesn't exist. Set the 'nonexistent' flag as true. +*/ +if (IS_ERR (sc->tp_format)) { + sc->nonexistent = true; +return PTR_ERR (sc->tp_format); + } +if (syscall__alloc_arg_fmts (sc,IS_ERR (sc->tp_format) ?RAW_SYSCALL_ARGS_NUM : sc->tp_format->format.nr_fields))return -ENOMEM ; -if (IS_ERR (sc->tp_format)) -return PTR_ERR (sc->tp_format); - sc->args = sc->tp_format->format.fields;/* * We need to check and discard the first variable '__syscall_nr'
@@ -2117,11 +2123,8 @@ static struct syscall *trace__syscall_info(struct trace *trace, (err = trace__read_syscall_info(trace, id)) != 0) goto out_cant_read; -if (trace->syscalls.table[id].name ==NULL ) { -if (trace->syscalls.table[id].nonexistent) -return NULL ; +if (trace->syscalls.table && trace->syscalls.table[id].nonexistent) goto out_cant_read; - }return &trace->syscalls.table[id];
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 405/783 perf symbol: correction while adjusting symbol
In reply to Greg Kroah-HartmanFrom: Ajay Kaher <[email protected]>
[ Upstream commit 6f520ce17920b3cdfbd2479b3ccf27f9706219d0 ]
perf doesn't provide proper symbol information for specially crafted .debug files.
Sometimes .debug file may not have similar program header as runtime ELF file. For example if we generate .debug file using objcopy --only-keep-debug resulting file will not contain .text, .data and other runtime sections. That means corresponding program headers will have zero FileSiz and modified Offset.
Example: program header of text section of libxxx.so:
Type Offset VirtAddr PhysAddr
FileSiz MemSiz Flags Align
LOAD 0x00000000003d3000 0x00000000003d3000 0x00000000003d3000
0x000000000055ae80 0x000000000055ae80 R E 0x1000
Same program header after executing:
objcopy --only-keep-debug libxxx.so libxxx.so.debug
LOAD 0x0000000000001000 0x00000000003d3000 0x00000000003d3000
0x0000000000000000 0x000000000055ae80 R E 0x1000
Offset and FileSiz have been changed.
Following formula will not provide correct value, if program header taken from .debug file (syms_ss):
sym.st_value -= phdr.p_vaddr - phdr.p_offset;
Correct program header information is located inside runtime ELF file (runtime_ss).
--- tools/perf/util/symbol-elf.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/util/symbol-elf.c +1 -1
@@ -1247,7 +1247,7 @@ int dso__load_sym(struct dso *dso, struct map *map, struct symsrc *syms_ss, (!used_opd && syms_ss->adjust_symbols)) {GElf_Phdr phdr; -if (elf_read_program_header (syms_ss->elf, +if (elf_read_program_header (runtime_ss->elf, (u64 )sym.st_value, &phdr)) { pr_debug4("%s: failed to find program header for " "symbol: %s st_value: %#" PRIx64 "\n",
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 406/783 HSI: omap_ssi_core: Fix error handling in ssi_init()
In reply to Greg Kroah-HartmanFrom: Yuan Can <[email protected]>
[ Upstream commit 3ffa9f713c39a213a08d9ff13ab983a8aa5d8b5d ]
The ssi_init() returns the platform_driver_register() directly without checking its return value, if platform_driver_register() failed, the ssi_pdriver is not unregistered.
Fix by unregister ssi_pdriver when the last platform_driver_register() failed.
--- drivers/hsi/controllers/omap_ssi_core.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
drivers/hsi/controllers/omap_ssi_core.c +7 -1
@@ -631,7 +631,13 @@ static int __init ssi_init(void) {if (ret)return ret; -return platform_driver_register (&ssi_port_pdriver); + ret =platform_driver_register (&ssi_port_pdriver); +if (ret) { +platform_driver_unregister (&ssi_pdriver); +return ret; + } + +return 0 ; }module_init (ssi_init);
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 407/783 power: supply: fix null pointer dereferencing in power_supply_get_battery_info
In reply to Greg Kroah-HartmanFrom: ruanjinjie <[email protected]>
[ Upstream commit 104bb8a663451404a26331263ce5b96c34504049 ]
when kmalloc() fail to allocate memory in kasprintf(), propname will be NULL, strcmp() called by of_get_property() will cause null pointer dereference.
So return ENOMEM if kasprintf() return NULL pointer.
--- drivers/power/supply/power_supply_core.c | 5 +++++ 1 file changed, 5 insertions(+)
drivers/power/supply/power_supply_core.c +5 -0
@@ -677,6 +677,11 @@ int power_supply_get_battery_info(struct power_supply *psy,int i, tab_len, size; propname =kasprintf (GFP_KERNEL ,"ocv-capacity-table-%d" , index); +if (!propname) { +power_supply_put_battery_info (psy, info); + err = -ENOMEM ; + goto out_put_node; + } list =of_get_property (battery_np, propname, &size);if (!list || !size) {dev_err (&psy->dev,"failed to get %s\n" , propname);
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 408/783 RDMA/siw: Fix pointer cast warning
In reply to Greg Kroah-HartmanFrom: Arnd Bergmann <[email protected]>
[ Upstream commit 5244ca88671a1981ceec09c5c8809f003e6a62aa ]
The previous build fix left a remaining issue in configurations with 64-bit dma_addr_t on 32-bit architectures:
drivers/infiniband/sw/siw/siw_qp_tx.c: In function 'siw_get_pblpage':drivers/infiniband/sw/siw/siw_qp_tx.c:32:37: error: cast to pointer from integer of different size [-Werror=int-to-pointer-cast]
32 | return virt_to_page((void *)paddr);
| ^
Use the same double cast here that the driver uses elsewhere to convert between dma_addr_t and void*.
--- drivers/infiniband/sw/siw/siw_qp_tx.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/infiniband/sw/siw/siw_qp_tx.c +1 -1
@@ -29,7 +29,7 @@ static struct page *siw_get_pblpage(struct siw_mem *mem, u64 addr, int *idx)dma_addr_t paddr =siw_pbl_get_buffer (pbl, offset,NULL , idx);if (paddr) -return virt_to_page ((void *)paddr); +return virt_to_page ((void *)(uintptr_t )paddr);return NULL ; }
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 409/783 iommu/sun50i: Fix reset release
In reply to Greg Kroah-HartmanFrom: Jernej Skrabec <[email protected]>
[ Upstream commit 9ad0c1252e84dbc664f0462707182245ed603237 ]
Reset signal is asserted by writing 0 to the corresponding locations of masters we want to reset. So in order to deassert all reset signals, we should write 1's to all locations.
Current code writes 1's to locations of masters which were just reset which is good. However, at the same time it also writes 0's to other locations and thus asserts reset signals of remaining masters. Fix code by writing all 1's when we want to deassert all reset signals.
This bug was discovered when working with Cedrus (video decoder). When it faulted, display went blank due to reset signal assertion.
--- drivers/iommu/sun50i-iommu.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/iommu/sun50i-iommu.c +2 -1
@@ -28,6 +28,7 @@#include <linux/types.h> #define IOMMU_RESET_REG 0x010 +#define IOMMU_RESET_RELEASE_ALL 0xffffffff#define IOMMU_ENABLE_REG 0x020#define IOMMU_ENABLE_ENABLE BIT(0)
@@ -905,7 +906,7 @@ static irqreturn_t sun50i_iommu_irq(int irq, void *dev_id)iommu_write (iommu,IOMMU_INT_CLR_REG , status);iommu_write (iommu,IOMMU_RESET_REG , ~status); -iommu_write (iommu,IOMMU_RESET_REG , status); +iommu_write (iommu,IOMMU_RESET_REG ,IOMMU_RESET_RELEASE_ALL );spin_unlock (&iommu->iommu_lock);
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 410/783 iommu/sun50i: Consider all fault sources for reset
In reply to Greg Kroah-HartmanFrom: Jernej Skrabec <[email protected]>
[ Upstream commit cef20703e2b2276aaa402ec5a65ec9a09963b83e ]
We have to reset masters for all faults - permissions, L1 fault or L2 fault. Currently it's done only for permissions. If other type of fault happens, master is in locked up state. Fix that by really considering all fault sources.
--- drivers/iommu/sun50i-iommu.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/iommu/sun50i-iommu.c +6 -2
@@ -881,8 +881,8 @@ static phys_addr_t sun50i_iommu_handle_perm_irq(struct sun50i_iommu *iommu)static irqreturn_t sun50i_iommu_irq (int irq,void *dev_id) { +u32 status, l1_status, l2_status, resets;struct sun50i_iommu *iommu = dev_id; -u32 status;spin_lock (&iommu->iommu_lock);
@@ -892,6 +892,9 @@ static irqreturn_t sun50i_iommu_irq(int irq, void *dev_id)return IRQ_NONE ; } + l1_status =iommu_read (iommu,IOMMU_L1PG_INT_REG ); + l2_status =iommu_read (iommu,IOMMU_L2PG_INT_REG ); +if (status &IOMMU_INT_INVALID_L2PG ) sun50i_iommu_handle_pt_irq(iommu, IOMMU_INT_ERR_ADDR_L2_REG,
@@ -905,7 +908,8 @@ static irqreturn_t sun50i_iommu_irq(int irq, void *dev_id)iommu_write (iommu,IOMMU_INT_CLR_REG , status); -iommu_write (iommu,IOMMU_RESET_REG , ~status); + resets = (status | l1_status | l2_status) &IOMMU_INT_MASTER_MASK ; +iommu_write (iommu,IOMMU_RESET_REG , ~resets);iommu_write (iommu,IOMMU_RESET_REG ,IOMMU_RESET_RELEASE_ALL );spin_unlock (&iommu->iommu_lock);
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 411/783 iommu/sun50i: Fix R/W permission check
In reply to Greg Kroah-HartmanFrom: Jernej Skrabec <[email protected]>
[ Upstream commit eac0104dc69be50bed86926d6f32e82b44f8c921 ]
Because driver has enum type permissions and iommu subsystem has bitmap type, we have to be careful how check for combined read and write permissions is done. In such case, we have to mask both permissions and check that both are set at the same time.
Current code just masks both flags but doesn't check that both are set. In short, it always sets R/W permission, regardles if requested permissions were RO, WO or RW. Fix that.
--- drivers/iommu/sun50i-iommu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iommu/sun50i-iommu.c +1 -1
@@ -272,7 +272,7 @@ static u32 sun50i_mk_pte(phys_addr_t page, int prot)enum sun50i_iommu_aci aci;u32 flags =0 ; -if (prot & (IOMMU_READ |IOMMU_WRITE )) +if ((prot & (IOMMU_READ |IOMMU_WRITE )) == (IOMMU_READ |IOMMU_WRITE )) aci =SUN50I_IOMMU_ACI_RD_WR ;else if (prot &IOMMU_READ ) aci =SUN50I_IOMMU_ACI_RD ;
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 412/783 iommu/sun50i: Fix flush size
In reply to Greg Kroah-HartmanFrom: Jernej Skrabec <[email protected]>
[ Upstream commit 67a8a67f9eceb72e4c73d1d09ed9ab04f4b8e12d ]
Function sun50i_table_flush() takes number of entries as an argument, not number of bytes. Fix that mistake in sun50i_dte_get_page_table().
--- drivers/iommu/sun50i-iommu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iommu/sun50i-iommu.c +1 -1
@@ -513,7 +513,7 @@ static u32 *sun50i_dte_get_page_table(struct sun50i_iommu_domain *sun50i_domain,sun50i_iommu_free_page_table (iommu, drop_pt); } -sun50i_table_flush (sun50i_domain, page_table,PT_SIZE ); +sun50i_table_flush (sun50i_domain, page_table,NUM_PT_ENTRIES );sun50i_table_flush (sun50i_domain, dte_addr,1 );return page_table;
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 413/783 phy: usb: s2 WoL wakeup_count not incremented for USB->Eth devices
In reply to Greg Kroah-HartmanFrom: Al Cooper <[email protected]>
[ Upstream commit f7fc5b7090372fc4dd7798c874635ca41b8ba733 ]
The PHY's "wakeup_count" is not incrementing when waking from WoL. The wakeup count can be found in sysfs at:/sys/bus/platform/devices/rdb/*.usb-phy/power/wakeup_count. The problem is that the system wakup event handler was being passed the wrong "device" by the PHY driver.
--- drivers/phy/broadcom/phy-brcm-usb.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/phy/broadcom/phy-brcm-usb.c +3 -3
@@ -101,9 +101,9 @@ static int brcm_pm_notifier(struct notifier_block *notifier,static irqreturn_t brcm_usb_phy_wake_isr (int irq,void *dev_id) { -struct phy *gphy = dev_id; +struct device *dev = dev_id; -pm_wakeup_event (&gphy->dev,0 ); +pm_wakeup_event (dev,0 );return IRQ_HANDLED ; }
@@ -437,7 +437,7 @@ static int brcm_usb_phy_dvr_init(struct platform_device *pdev,if (priv->wake_irq >=0 ) { err =devm_request_irq (dev, priv->wake_irq, brcm_usb_phy_wake_isr,0 , -dev_name (dev), gphy); +dev_name (dev), dev);if (err <0 )return err;device_set_wakeup_capable (dev,1 );
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 414/783 include/uapi/linux/swab: Fix potentially missing __always_inline
In reply to Greg Kroah-HartmanFrom: Matt Redfearn <[email protected]>
[ Upstream commit defbab270d45e32b068e7e73c3567232d745c60f ]
Commit bc27fb68aaad ("include/uapi/linux/byteorder, swab: force inlining of some byteswap operations") added __always_inline to swab functions and commit 283d75737837 ("uapi/linux/stddef.h: Provide __always_inline to userspace headers") added a definition of __always_inline for use in exported headers when the kernel's compiler.h is not available.
However, since swab.h does not include stddef.h, if the header soup does not indirectly include it, the definition of __always_inline is missing, resulting in a compilation failure, which was observed compiling the perf tool using exported headers containing this commit:
In file included from /usr/include/linux/byteorder/little_endian.h:12:0,
from /usr/include/asm/byteorder.h:14,
from tools/include/uapi/linux/perf_event.h:20,
from perf.h:8,
from builtin-bench.c:18:/usr/include/linux/swab.h:160:8: error: unknown type name `__always_inline'
static __always_inline __u16 __swab16p(const __u16 *p)
Fix this by replacing the inclusion of linux/compiler.h with linux/stddef.h to ensure that we pick up that definition if required, without relying on it's indirect inclusion. compiler.h is then included indirectly, via stddef.h.
--- include/uapi/linux/swab.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
include/uapi/linux/swab.h +1 -1
@@ -3,7 +3,7 @@#define _UAPI_LINUX_SWAB_H#include <linux/types.h> -#include <linux/compiler.h> +#include <linux/stddef.h> #include <asm/bitsperlong.h> #include <asm/swab.h>
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 415/783 pwm: tegra: Improve required rate calculation
In reply to Greg Kroah-HartmanFrom: Jon Hunter <[email protected]>
[ Upstream commit f271946117dde2ca8741b8138b347b2d68e6ad56 ]
For the case where dev_pm_opp_set_rate() is called to set the PWM clock rate, the requested rate is calculated as ...
required_clk_rate = (NSEC_PER_SEC / period_ns) << PWM_DUTY_WIDTH;
The above calculation may lead to rounding errors because the NSEC_PER_SEC is divided by 'period_ns' before applying the PWM_DUTY_WIDTH multiplication factor. For example, if the period is 45334ns, the above calculation yields a rate of 5646848Hz instead of 5646976Hz. Fix this by applying the multiplication factor before dividing and using the DIV_ROUND_UP macro which yields the expected result of 5646976Hz.
--- drivers/pwm/pwm-tegra.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/pwm/pwm-tegra.c +2 -2
@@ -142,8 +142,8 @@ static int tegra_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm,* source clock rate as required_clk_rate, PWM controller will * be able to configure the requested period. */ - required_clk_rate = - (NSEC_PER_SEC / period_ns) <<PWM_DUTY_WIDTH ; + required_clk_rate =DIV_ROUND_UP_ULL (NSEC_PER_SEC <<PWM_DUTY_WIDTH , + period_ns); err =clk_set_rate (pc->clk, required_clk_rate);if (err <0 )
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 416/783 dmaengine: idxd: Fix crc_val field for completion record
In reply to Greg Kroah-HartmanFrom: Fenghua Yu <[email protected]>
[ Upstream commit dc901d98b1fe6e52ab81cd3e0879379168e06daa ]
The crc_val in the completion record should be 64 bits and not 32 bits.
--- include/uapi/linux/idxd.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
include/uapi/linux/idxd.h +1 -1
@@ -188,7 +188,7 @@ struct dsa_completion_record { };uint32_t delta_rec_size; -uint32_t crc_val; +uint64_t crc_val;/* DIF check & strip */ struct {
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 417/783 rtc: rtc-cmos: Do not check ACPI_FADT_LOW_POWER_S0
In reply to Greg Kroah-HartmanFrom: Rafael J. Wysocki <[email protected]>
[ Upstream commit 6492fed7d8c95f53b0b804ef541324d924d95d41 ]
The ACPI_FADT_LOW_POWER_S0 flag merely means that it is better to use low-power S0 idle on the given platform than S3 (provided that the latter is supported) and it doesn't preclude using either of them (which of them will be used depends on the choices made by user space).
For this reason, there is no benefit from checking that flag in use_acpi_alarm_quirks().
First off, it cannot be a bug to do S3 with use_acpi_alarm set, because S3 can be used on systems with ACPI_FADT_LOW_POWER_S0 and it must work if really supported, so the ACPI_FADT_LOW_POWER_S0 check is not needed to protect the S3-capable systems from failing.
Second, suspend-to-idle can be carried out on a system with ACPI_FADT_LOW_POWER_S0 unset and it is expected to work, so if setting use_acpi_alarm is needed to handle that case correctly, it should be set regardless of the ACPI_FADT_LOW_POWER_S0 value.
Accordingly, drop the ACPI_FADT_LOW_POWER_S0 check from use_acpi_alarm_quirks().
Stable-dep-of: 83ebb7b3036d ("rtc: cmos: Disable ACPI RTC event on removal")
--- drivers/rtc/rtc-cmos.c | 3 --- 1 file changed, 3 deletions(-)
drivers/rtc/rtc-cmos.c +0 -3
@@ -1265,9 +1265,6 @@ static void use_acpi_alarm_quirks(void)if (boot_cpu_data.x86_vendor !=X86_VENDOR_INTEL )return ; -if (!(acpi_gbl_FADT.flags &ACPI_FADT_LOW_POWER_S0 )) -return ; -if (!is_hpet_enabled ())return ;
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 418/783 rtc: cmos: Fix event handler registration ordering issue
In reply to Greg Kroah-HartmanFrom: Rafael J. Wysocki <[email protected]>
[ Upstream commit 4919d3eb2ec0ee364f7e3cf2d99646c1b224fae8 ]
Because acpi_install_fixed_event_handler() enables the event automatically on success, it is incorrect to call it before the handler routine passed to it is ready to handle events.
Unfortunately, the rtc-cmos driver does exactly the incorrect thing by calling cmos_wake_setup(), which passes rtc_handler() to acpi_install_fixed_event_handler(), before cmos_do_probe(), because rtc_handler() uses dev_get_drvdata() to get to the cmos object pointer and the driver data pointer is only populated in cmos_do_probe().
This leads to a NULL pointer dereference in rtc_handler() on boot if the RTC fixed event happens to be active at the init time.
To address this issue, change the initialization ordering of the driver so that cmos_wake_setup() is always called after a successful cmos_do_probe() call.
While at it, change cmos_pnp_probe() to call cmos_do_probe() after the initial if () statement used for computing the IRQ argument to be passed to cmos_do_probe() which is cleaner than calling it in each branch of that if () (local variable "irq" can be of type int, because it is passed to that function as an argument of type int).
Note that commit 6492fed7d8c9 ("rtc: rtc-cmos: Do not check ACPI_FADT_LOW_POWER_S0") caused this issue to affect a larger number of systems, because previously it only affected systems with ACPI_FADT_LOW_POWER_S0 set, but it is present regardless of that commit.
Stable-dep-of: 83ebb7b3036d ("rtc: cmos: Disable ACPI RTC event on removal")
--- drivers/rtc/rtc-cmos.c | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-)
drivers/rtc/rtc-cmos.c +19 -10
@@ -1357,10 +1357,10 @@ static void cmos_check_acpi_rtc_status(struct device *dev,static int cmos_pnp_probe (struct pnp_dev *pnp,const struct pnp_device_id *id) { -cmos_wake_setup (&pnp->dev); +int irq, ret;if (pnp_port_start (pnp,0 ) ==0x70 && !pnp_irq_valid (pnp,0 )) { -unsigned int irq =0 ; + irq =0 ;#ifdef CONFIG_X86 /* Some machines contain a PNP entry for the RTC, but * don't define the IRQ. It should always be safe to
@@ -1369,13 +1369,17 @@ static int cmos_pnp_probe(struct pnp_dev *pnp, const struct pnp_device_id *id)if (nr_legacy_irqs ()) irq =RTC_IRQ ;#endif -return cmos_do_probe (&pnp->dev, -pnp_get_resource (pnp,IORESOURCE_IO ,0 ), irq); }else { -return cmos_do_probe (&pnp->dev, -pnp_get_resource (pnp,IORESOURCE_IO ,0 ), -pnp_irq (pnp,0 )); + irq =pnp_irq (pnp,0 ); } + + ret =cmos_do_probe (&pnp->dev,pnp_get_resource (pnp,IORESOURCE_IO ,0 ), irq); +if (ret) +return ret; + +cmos_wake_setup (&pnp->dev); + +return 0 ; }static void cmos_pnp_remove (struct pnp_dev *pnp)
@@ -1459,10 +1463,9 @@ static inline void cmos_of_init(struct platform_device *pdev) {}static int __init cmos_platform_probe (struct platform_device *pdev) {struct resource *resource; -int irq; +int irq, ret;cmos_of_init (pdev); -cmos_wake_setup (&pdev->dev);if (RTC_IOMAPPED ) resource =platform_get_resource (pdev,IORESOURCE_IO ,0 );
@@ -1472,7 +1475,13 @@ static int __init cmos_platform_probe(struct platform_device *pdev)if (irq <0 ) irq =-1 ; -return cmos_do_probe (&pdev->dev, resource, irq); + ret =cmos_do_probe (&pdev->dev, resource, irq); +if (ret) +return ret; + +cmos_wake_setup (&pdev->dev); + +return 0 ; }static int cmos_platform_remove (struct platform_device *pdev)
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 419/783 rtc: cmos: Fix wake alarm breakage
In reply to Greg Kroah-HartmanFrom: Rafael J. Wysocki <[email protected]>
[ Upstream commit 0782b66ed2fbb035dda76111df0954515e417b24 ]
Commit 4919d3eb2ec0 ("rtc: cmos: Fix event handler registration ordering issue") overlooked the fact that cmos_do_probe() depended on the preparations carried out by cmos_wake_setup() and the wake alarm stopped working after the ordering of them had been changed.
Address this by partially reverting commit 4919d3eb2ec0 so that cmos_wake_setup() is called before cmos_do_probe() again and moving the rtc_wake_setup() invocation from cmos_wake_setup() directly to the callers of cmos_do_probe() where it will happen after a successful completion of the latter.
Stable-dep-of: 83ebb7b3036d ("rtc: cmos: Disable ACPI RTC event on removal")
--- drivers/rtc/rtc-cmos.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-)
drivers/rtc/rtc-cmos.c +8 -3
@@ -1238,6 +1238,9 @@ static u32 rtc_handler(void *context)static inline void rtc_wake_setup (struct device *dev) { +if (acpi_disabled) +return ; +acpi_install_fixed_event_handler (ACPI_EVENT_RTC , rtc_handler, dev);/* * After the RTC handler is installed, the Fixed_RTC event should
@@ -1291,7 +1294,6 @@ static void cmos_wake_setup(struct device *dev)use_acpi_alarm_quirks (); -rtc_wake_setup (dev); acpi_rtc_info.wake_on = rtc_wake_on; acpi_rtc_info.wake_off = rtc_wake_off;
@@ -1359,6 +1361,8 @@ static int cmos_pnp_probe(struct pnp_dev *pnp, const struct pnp_device_id *id) {int irq, ret; +cmos_wake_setup (&pnp->dev); +if (pnp_port_start (pnp,0 ) ==0x70 && !pnp_irq_valid (pnp,0 )) { irq =0 ;#ifdef CONFIG_X86
@@ -1377,7 +1381,7 @@ static int cmos_pnp_probe(struct pnp_dev *pnp, const struct pnp_device_id *id)if (ret)return ret; -cmos_wake_setup (&pnp->dev); +rtc_wake_setup (&pnp->dev);return 0 ; }
@@ -1466,6 +1470,7 @@ static int __init cmos_platform_probe(struct platform_device *pdev)int irq, ret;cmos_of_init (pdev); +cmos_wake_setup (&pdev->dev);if (RTC_IOMAPPED ) resource =platform_get_resource (pdev,IORESOURCE_IO ,0 );
@@ -1479,7 +1484,7 @@ static int __init cmos_platform_probe(struct platform_device *pdev)if (ret)return ret; -cmos_wake_setup (&pdev->dev); +rtc_wake_setup (&pdev->dev);return 0 ; }
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 420/783 rtc: cmos: fix build on non-ACPI platforms
In reply to Greg Kroah-HartmanFrom: Alexandre Belloni <[email protected]>
[ Upstream commit db4e955ae333567dea02822624106c0b96a2f84f ]
Now that rtc_wake_setup is called outside of cmos_wake_setup, it also need to be defined on non-ACPI platforms.
Stable-dep-of: 83ebb7b3036d ("rtc: cmos: Disable ACPI RTC event on removal")
--- drivers/rtc/rtc-cmos.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/rtc/rtc-cmos.c +3 -0
@@ -1351,6 +1351,9 @@ static void cmos_check_acpi_rtc_status(struct device *dev, { } +static void rtc_wake_setup (struct device *dev) +{ +}#endif #ifdef CONFIG_PNP
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 421/783 rtc: cmos: Call cmos_wake_setup() from cmos_do_probe()
In reply to Greg Kroah-HartmanFrom: Rafael J. Wysocki <[email protected]>
[ Upstream commit 508ccdfb86b21da37ad091003a4d4567709d5dfb ]
Notice that cmos_wake_setup() is the only user of acpi_rtc_info and it can operate on the cmos_rtc variable directly, so it need not set the platform_data pointer before cmos_do_probe() is called. Instead, it can be called by cmos_do_probe() in the case when the platform_data pointer is not set to implement the default behavior (which is to use the FADT information as long as ACPI support is enabled).
Modify the code accordingly.
While at it, drop a comment that doesn't really match the code it is supposed to be describing.
Stable-dep-of: 83ebb7b3036d ("rtc: cmos: Disable ACPI RTC event on removal")
--- drivers/rtc/rtc-cmos.c | 47 ++++++++++++++++++++---------------------- 1 file changed, 22 insertions(+), 25 deletions(-)
drivers/rtc/rtc-cmos.c +22 -25
@@ -750,6 +750,8 @@ static irqreturn_t cmos_interrupt(int irq, void *p)return IRQ_NONE ; } +static void cmos_wake_setup (struct device *dev); +#ifdef CONFIG_PNP #define INITSECTION
@@ -833,19 +835,27 @@ cmos_do_probe(struct device *dev, struct resource *ports, int rtc_irq)if (info->address_space) address_space = info->address_space; -if (info->rtc_day_alarm && info->rtc_day_alarm <128 ) - cmos_rtc.day_alrm = info->rtc_day_alarm; -if (info->rtc_mon_alarm && info->rtc_mon_alarm <128 ) - cmos_rtc.mon_alrm = info->rtc_mon_alarm; -if (info->rtc_century && info->rtc_century <128 ) - cmos_rtc.century = info->rtc_century; + cmos_rtc.day_alrm = info->rtc_day_alarm; + cmos_rtc.mon_alrm = info->rtc_mon_alarm; + cmos_rtc.century = info->rtc_century;if (info->wake_on && info->wake_off) { cmos_rtc.wake_on = info->wake_on; cmos_rtc.wake_off = info->wake_off; } + }else { +cmos_wake_setup (dev); } +if (cmos_rtc.day_alrm >=128 ) + cmos_rtc.day_alrm =0 ; + +if (cmos_rtc.mon_alrm >=128 ) + cmos_rtc.mon_alrm =0 ; + +if (cmos_rtc.century >=128 ) + cmos_rtc.century =0 ; + cmos_rtc.dev = dev;dev_set_drvdata (dev, &cmos_rtc);
@@ -1280,13 +1290,6 @@ static void use_acpi_alarm_quirks(void)static inline void use_acpi_alarm_quirks (void ) { }#endif -/* Every ACPI platform has a mc146818 compatible "cmos rtc". Here we find -* its device node and pass extra config data. This helps its driver use -* capabilities that the now-obsolete mc146818 didn't have, and informs it -* that this board's RTC is wakeup-capable (per ACPI spec). -*/ -static struct cmos_rtc_board_info acpi_rtc_info; -static void cmos_wake_setup (struct device *dev) {if (acpi_disabled)
@@ -1294,26 +1297,23 @@ static void cmos_wake_setup(struct device *dev)use_acpi_alarm_quirks (); - acpi_rtc_info.wake_on = rtc_wake_on; - acpi_rtc_info.wake_off = rtc_wake_off; + cmos_rtc.wake_on = rtc_wake_on; + cmos_rtc.wake_off = rtc_wake_off; -/* workaround bug in some ACPI tables */ +/* ACPI tables bug workaround. */ if (acpi_gbl_FADT.month_alarm && !acpi_gbl_FADT.day_alarm) {dev_dbg (dev,"bogus FADT month_alarm (%d)\n" , acpi_gbl_FADT.month_alarm); acpi_gbl_FADT.month_alarm =0 ; } - acpi_rtc_info.rtc_day_alarm = acpi_gbl_FADT.day_alarm; - acpi_rtc_info.rtc_mon_alarm = acpi_gbl_FADT.month_alarm; - acpi_rtc_info.rtc_century = acpi_gbl_FADT.century; + cmos_rtc.day_alrm = acpi_gbl_FADT.day_alarm; + cmos_rtc.mon_alrm = acpi_gbl_FADT.month_alarm; + cmos_rtc.century = acpi_gbl_FADT.century; -/* NOTE: S4_RTC_WAKE is NOT currently useful to Linux */ if (acpi_gbl_FADT.flags &ACPI_FADT_S4_RTC_WAKE )dev_info (dev,"RTC can wake from S4\n" ); - dev->platform_data = &acpi_rtc_info; -/* RTC always wakes from S1/S2/S3, and often S4/STD */ device_init_wakeup (dev,1 ); }
@@ -1364,8 +1364,6 @@ static int cmos_pnp_probe(struct pnp_dev *pnp, const struct pnp_device_id *id) {int irq, ret; -cmos_wake_setup (&pnp->dev); -if (pnp_port_start (pnp,0 ) ==0x70 && !pnp_irq_valid (pnp,0 )) { irq =0 ;#ifdef CONFIG_X86
@@ -1473,7 +1471,6 @@ static int __init cmos_platform_probe(struct platform_device *pdev)int irq, ret;cmos_of_init (pdev); -cmos_wake_setup (&pdev->dev);if (RTC_IOMAPPED ) resource =platform_get_resource (pdev,IORESOURCE_IO ,0 );
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 422/783 rtc: cmos: Call rtc_wake_setup() from cmos_do_probe()
In reply to Greg Kroah-HartmanFrom: Rafael J. Wysocki <[email protected]>
[ Upstream commit 375bbba09692fe4c5218eddee8e312dd733fa846 ]
To reduce code duplication, move the invocation of rtc_wake_setup() into cmos_do_probe() and simplify the callers of the latter.
No intentional functional impact.
Stable-dep-of: 83ebb7b3036d ("rtc: cmos: Disable ACPI RTC event on removal")
--- drivers/rtc/rtc-cmos.c | 28 ++++++++++++---------------- 1 file changed, 12 insertions(+), 16 deletions(-)
drivers/rtc/rtc-cmos.c +12 -16
@@ -750,6 +750,7 @@ static irqreturn_t cmos_interrupt(int irq, void *p)return IRQ_NONE ; } +static inline void rtc_wake_setup (struct device *dev);static void cmos_wake_setup (struct device *dev);#ifdef CONFIG_PNP
@@ -943,6 +944,13 @@ cmos_do_probe(struct device *dev, struct resource *ports, int rtc_irq)if (rtc_nvmem_register (cmos_rtc.rtc, &nvmem_cfg))dev_err (dev,"nvmem registration failed\n" ); +/* +* Everything has gone well so far, so by default register a handler for +* the ACPI RTC fixed event. +*/ +if (!info) +rtc_wake_setup (dev); +dev_info (dev,"%s%s, %d bytes nvram%s\n" , !is_valid_irq (rtc_irq) ?"no alarms" : cmos_rtc.mon_alrm ? "alarms up to one year" :
@@ -1362,7 +1370,7 @@ static void rtc_wake_setup(struct device *dev)static int cmos_pnp_probe (struct pnp_dev *pnp,const struct pnp_device_id *id) { -int irq, ret; +int irq;if (pnp_port_start (pnp,0 ) ==0x70 && !pnp_irq_valid (pnp,0 )) { irq =0 ;
@@ -1378,13 +1386,7 @@ static int cmos_pnp_probe(struct pnp_dev *pnp, const struct pnp_device_id *id) irq =pnp_irq (pnp,0 ); } - ret =cmos_do_probe (&pnp->dev,pnp_get_resource (pnp,IORESOURCE_IO ,0 ), irq); -if (ret) -return ret; - -rtc_wake_setup (&pnp->dev); - -return 0 ; +return cmos_do_probe (&pnp->dev,pnp_get_resource (pnp,IORESOURCE_IO ,0 ), irq); }static void cmos_pnp_remove (struct pnp_dev *pnp)
@@ -1468,7 +1470,7 @@ static inline void cmos_of_init(struct platform_device *pdev) {}static int __init cmos_platform_probe (struct platform_device *pdev) {struct resource *resource; -int irq, ret; +int irq;cmos_of_init (pdev);
@@ -1480,13 +1482,7 @@ static int __init cmos_platform_probe(struct platform_device *pdev)if (irq <0 ) irq =-1 ; - ret =cmos_do_probe (&pdev->dev, resource, irq); -if (ret) -return ret; - -rtc_wake_setup (&pdev->dev); - -return 0 ; +return cmos_do_probe (&pdev->dev, resource, irq); }static int cmos_platform_remove (struct platform_device *pdev)
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 423/783 rtc: cmos: Eliminate forward declarations of some functions
In reply to Greg Kroah-HartmanFrom: Rafael J. Wysocki <[email protected]>
[ Upstream commit dca4d3b71c8a09a16951add656711fbd6f5bfbb0 ]
Reorder the ACPI-related code before cmos_do_probe() so as to eliminate excessive forward declarations of some functions.
While at it, for consistency, add the inline modifier to the definitions of empty stub static funtions and remove it from the corresponding definitions of functions with non-empty bodies.
No intentional functional impact.
Stable-dep-of: 83ebb7b3036d ("rtc: cmos: Disable ACPI RTC event on removal")
--- drivers/rtc/rtc-cmos.c | 304 ++++++++++++++++++++--------------------- 1 file changed, 149 insertions(+), 155 deletions(-)
drivers/rtc/rtc-cmos.c +149 -155
@@ -750,8 +750,155 @@ static irqreturn_t cmos_interrupt(int irq, void *p)return IRQ_NONE ; } -static inline void rtc_wake_setup (struct device *dev); -static void cmos_wake_setup (struct device *dev); +#ifdef CONFIG_ACPI + +#include <linux/acpi.h> + +static u32 rtc_handler (void *context) +{ +struct device *dev = context; +struct cmos_rtc *cmos =dev_get_drvdata (dev); +unsigned char rtc_control =0 ; +unsigned char rtc_intr; +unsigned long flags; + + +/* +* Always update rtc irq when ACPI is used as RTC Alarm. +* Or else, ACPI SCI is enabled during suspend/resume only, +* update rtc irq in that case. +*/ +if (cmos_use_acpi_alarm ()) +cmos_interrupt (0 , (void *)cmos->rtc); +else { +/* Fix me: can we use cmos_interrupt() here as well? */ +spin_lock_irqsave (&rtc_lock, flags); +if (cmos_rtc.suspend_ctrl) + rtc_control =CMOS_READ (RTC_CONTROL ); +if (rtc_control &RTC_AIE ) { + cmos_rtc.suspend_ctrl &= ~RTC_AIE ; +CMOS_WRITE (rtc_control,RTC_CONTROL ); + rtc_intr =CMOS_READ (RTC_INTR_FLAGS ); +rtc_update_irq (cmos->rtc,1 , rtc_intr); + } +spin_unlock_irqrestore (&rtc_lock, flags); + } + +pm_wakeup_hard_event (dev); +acpi_clear_event (ACPI_EVENT_RTC ); +acpi_disable_event (ACPI_EVENT_RTC ,0 ); +return ACPI_INTERRUPT_HANDLED ; +} + +static void rtc_wake_setup (struct device *dev) +{ +if (acpi_disabled) +return ; + +acpi_install_fixed_event_handler (ACPI_EVENT_RTC , rtc_handler, dev); +/* +* After the RTC handler is installed, the Fixed_RTC event should +* be disabled. Only when the RTC alarm is set will it be enabled. +*/ +acpi_clear_event (ACPI_EVENT_RTC ); +acpi_disable_event (ACPI_EVENT_RTC ,0 ); +} + +static void rtc_wake_on (struct device *dev) +{ +acpi_clear_event (ACPI_EVENT_RTC ); +acpi_enable_event (ACPI_EVENT_RTC ,0 ); +} + +static void rtc_wake_off (struct device *dev) +{ +acpi_disable_event (ACPI_EVENT_RTC ,0 ); +} + +#ifdef CONFIG_X86 +/* Enable use_acpi_alarm mode for Intel platforms no earlier than 2015 */ +static void use_acpi_alarm_quirks (void ) +{ +if (boot_cpu_data.x86_vendor !=X86_VENDOR_INTEL ) +return ; + +if (!is_hpet_enabled ()) +return ; + +if (dmi_get_bios_year () <2015 ) +return ; + + use_acpi_alarm = true; +} +#else +static inline void use_acpi_alarm_quirks (void ) { } +#endif + +static void cmos_wake_setup (struct device *dev) +{ +if (acpi_disabled) +return ; + +use_acpi_alarm_quirks (); + + cmos_rtc.wake_on = rtc_wake_on; + cmos_rtc.wake_off = rtc_wake_off; + +/* ACPI tables bug workaround. */ +if (acpi_gbl_FADT.month_alarm && !acpi_gbl_FADT.day_alarm) { +dev_dbg (dev,"bogus FADT month_alarm (%d)\n" , + acpi_gbl_FADT.month_alarm); + acpi_gbl_FADT.month_alarm =0 ; + } + + cmos_rtc.day_alrm = acpi_gbl_FADT.day_alarm; + cmos_rtc.mon_alrm = acpi_gbl_FADT.month_alarm; + cmos_rtc.century = acpi_gbl_FADT.century; + +if (acpi_gbl_FADT.flags &ACPI_FADT_S4_RTC_WAKE ) +dev_info (dev,"RTC can wake from S4\n" ); + +/* RTC always wakes from S1/S2/S3, and often S4/STD */ +device_init_wakeup (dev,1 ); +} + +static void cmos_check_acpi_rtc_status (struct device *dev, +unsigned char *rtc_control) +{ +struct cmos_rtc *cmos =dev_get_drvdata (dev); +acpi_event_status rtc_status; +acpi_status status; + +if (acpi_gbl_FADT.flags &ACPI_FADT_FIXED_RTC ) +return ; + + status =acpi_get_event_status (ACPI_EVENT_RTC , &rtc_status); +if (ACPI_FAILURE (status)) { +dev_err (dev,"Could not get RTC status\n" ); + }else if (rtc_status &ACPI_EVENT_FLAG_SET ) { +unsigned char mask; + *rtc_control &= ~RTC_AIE ; +CMOS_WRITE (*rtc_control,RTC_CONTROL ); + mask =CMOS_READ (RTC_INTR_FLAGS ); +rtc_update_irq (cmos->rtc,1 , mask); + } +} + +#else /* !CONFIG_ACPI */ + +static inline void rtc_wake_setup (struct device *dev) +{ +} + +static inline void cmos_wake_setup (struct device *dev) +{ +} + +static inline void cmos_check_acpi_rtc_status (struct device *dev, +unsigned char *rtc_control) +{ +} +#endif /* CONFIG_ACPI */ #ifdef CONFIG_PNP #define INITSECTION
@@ -1145,9 +1292,6 @@ static void cmos_check_wkalrm(struct device *dev) } } -static void cmos_check_acpi_rtc_status (struct device *dev, -unsigned char *rtc_control); -static int __maybe_unused cmos_resume (struct device *dev) {struct cmos_rtc *cmos =dev_get_drvdata (dev);
@@ -1214,156 +1358,6 @@ static SIMPLE_DEV_PM_OPS(cmos_pm_ops, cmos_suspend, cmos_resume);* predate even PNPBIOS should set up platform_bus devices. */ -#ifdef CONFIG_ACPI - -#include <linux/acpi.h> - -static u32 rtc_handler (void *context) -{ -struct device *dev = context; -struct cmos_rtc *cmos =dev_get_drvdata (dev); -unsigned char rtc_control =0 ; -unsigned char rtc_intr; -unsigned long flags; - - -/* -* Always update rtc irq when ACPI is used as RTC Alarm. -* Or else, ACPI SCI is enabled during suspend/resume only, -* update rtc irq in that case. -*/ -if (cmos_use_acpi_alarm ()) -cmos_interrupt (0 , (void *)cmos->rtc); -else { -/* Fix me: can we use cmos_interrupt() here as well? */ -spin_lock_irqsave (&rtc_lock, flags); -if (cmos_rtc.suspend_ctrl) - rtc_control =CMOS_READ (RTC_CONTROL ); -if (rtc_control &RTC_AIE ) { - cmos_rtc.suspend_ctrl &= ~RTC_AIE ; -CMOS_WRITE (rtc_control,RTC_CONTROL ); - rtc_intr =CMOS_READ (RTC_INTR_FLAGS ); -rtc_update_irq (cmos->rtc,1 , rtc_intr); - } -spin_unlock_irqrestore (&rtc_lock, flags); - } - -pm_wakeup_hard_event (dev); -acpi_clear_event (ACPI_EVENT_RTC ); -acpi_disable_event (ACPI_EVENT_RTC ,0 ); -return ACPI_INTERRUPT_HANDLED ; -} - -static inline void rtc_wake_setup (struct device *dev) -{ -if (acpi_disabled) -return ; - -acpi_install_fixed_event_handler (ACPI_EVENT_RTC , rtc_handler, dev); -/* -* After the RTC handler is installed, the Fixed_RTC event should -* be disabled. Only when the RTC alarm is set will it be enabled. -*/ -acpi_clear_event (ACPI_EVENT_RTC ); -acpi_disable_event (ACPI_EVENT_RTC ,0 ); -} - -static void rtc_wake_on (struct device *dev) -{ -acpi_clear_event (ACPI_EVENT_RTC ); -acpi_enable_event (ACPI_EVENT_RTC ,0 ); -} - -static void rtc_wake_off (struct device *dev) -{ -acpi_disable_event (ACPI_EVENT_RTC ,0 ); -} - -#ifdef CONFIG_X86 -/* Enable use_acpi_alarm mode for Intel platforms no earlier than 2015 */ -static void use_acpi_alarm_quirks (void ) -{ -if (boot_cpu_data.x86_vendor !=X86_VENDOR_INTEL ) -return ; - -if (!is_hpet_enabled ()) -return ; - -if (dmi_get_bios_year () <2015 ) -return ; - - use_acpi_alarm = true; -} -#else -static inline void use_acpi_alarm_quirks (void ) { } -#endif - -static void cmos_wake_setup (struct device *dev) -{ -if (acpi_disabled) -return ; - -use_acpi_alarm_quirks (); - - cmos_rtc.wake_on = rtc_wake_on; - cmos_rtc.wake_off = rtc_wake_off; - -/* ACPI tables bug workaround. */ -if (acpi_gbl_FADT.month_alarm && !acpi_gbl_FADT.day_alarm) { -dev_dbg (dev,"bogus FADT month_alarm (%d)\n" , - acpi_gbl_FADT.month_alarm); - acpi_gbl_FADT.month_alarm =0 ; - } - - cmos_rtc.day_alrm = acpi_gbl_FADT.day_alarm; - cmos_rtc.mon_alrm = acpi_gbl_FADT.month_alarm; - cmos_rtc.century = acpi_gbl_FADT.century; - -if (acpi_gbl_FADT.flags &ACPI_FADT_S4_RTC_WAKE ) -dev_info (dev,"RTC can wake from S4\n" ); - -/* RTC always wakes from S1/S2/S3, and often S4/STD */ -device_init_wakeup (dev,1 ); -} - -static void cmos_check_acpi_rtc_status (struct device *dev, -unsigned char *rtc_control) -{ -struct cmos_rtc *cmos =dev_get_drvdata (dev); -acpi_event_status rtc_status; -acpi_status status; - -if (acpi_gbl_FADT.flags &ACPI_FADT_FIXED_RTC ) -return ; - - status =acpi_get_event_status (ACPI_EVENT_RTC , &rtc_status); -if (ACPI_FAILURE (status)) { -dev_err (dev,"Could not get RTC status\n" ); - }else if (rtc_status &ACPI_EVENT_FLAG_SET ) { -unsigned char mask; - *rtc_control &= ~RTC_AIE ; -CMOS_WRITE (*rtc_control,RTC_CONTROL ); - mask =CMOS_READ (RTC_INTR_FLAGS ); -rtc_update_irq (cmos->rtc,1 , mask); - } -} - -#else - -static void cmos_wake_setup (struct device *dev) -{ -} - -static void cmos_check_acpi_rtc_status (struct device *dev, -unsigned char *rtc_control) -{ -} - -static void rtc_wake_setup (struct device *dev) -{ -} -#endif -#ifdef CONFIG_PNP #include <linux/pnp.h>
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 424/783 rtc: cmos: Rename ACPI-related functions
In reply to Greg Kroah-HartmanFrom: Rafael J. Wysocki <[email protected]>
[ Upstream commit d13e9ad9f5146f066a5c5a1cc993d09e4fb21ead ]
The names of rtc_wake_setup() and cmos_wake_setup() don't indicate that these functions are ACPI-related, which is the case, and the former doesn't really reflect the role of the function.
Rename them to acpi_rtc_event_setup() and acpi_cmos_wake_setup(), respectively, to address this shortcoming.
No intentional functional impact.
Stable-dep-of: 83ebb7b3036d ("rtc: cmos: Disable ACPI RTC event on removal")
--- drivers/rtc/rtc-cmos.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
drivers/rtc/rtc-cmos.c +6 -6
@@ -790,7 +790,7 @@ static u32 rtc_handler(void *context)return ACPI_INTERRUPT_HANDLED ; } -static void rtc_wake_setup (struct device *dev) +static void acpi_rtc_event_setup (struct device *dev) {if (acpi_disabled)return ;
@@ -834,7 +834,7 @@ static void use_acpi_alarm_quirks(void)static inline void use_acpi_alarm_quirks (void ) { }#endif -static void cmos_wake_setup (struct device *dev) +static void acpi_cmos_wake_setup (struct device *dev) {if (acpi_disabled)return ;
@@ -886,11 +886,11 @@ static void cmos_check_acpi_rtc_status(struct device *dev,#else /* !CONFIG_ACPI */ -static inline void rtc_wake_setup (struct device *dev) +static inline void acpi_rtc_event_setup (struct device *dev) { } -static inline void cmos_wake_setup (struct device *dev) +static inline void acpi_cmos_wake_setup (struct device *dev) { }
@@ -992,7 +992,7 @@ cmos_do_probe(struct device *dev, struct resource *ports, int rtc_irq) cmos_rtc.wake_off = info->wake_off; } }else { -cmos_wake_setup (dev); +acpi_cmos_wake_setup (dev); }if (cmos_rtc.day_alrm >=128 )
@@ -1096,7 +1096,7 @@ cmos_do_probe(struct device *dev, struct resource *ports, int rtc_irq)* the ACPI RTC fixed event. */ if (!info) -rtc_wake_setup (dev); +acpi_rtc_event_setup (dev); dev_info(dev, "%s%s, %d bytes nvram%s\n", !is_valid_irq(rtc_irq) ? "no alarms" :
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 425/783 rtc: cmos: Disable ACPI RTC event on removal
In reply to Greg Kroah-HartmanFrom: Rafael J. Wysocki <[email protected]>
[ Upstream commit 83ebb7b3036d151ee39a4a752018665648fc3bd4 ]
Make cmos_do_remove() drop the ACPI RTC fixed event handler so as to prevent it from operating on stale data in case the event triggers after driver removal.
--- drivers/rtc/rtc-cmos.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+)
drivers/rtc/rtc-cmos.c +15 -0
@@ -804,6 +804,14 @@ static void acpi_rtc_event_setup(struct device *dev)acpi_disable_event (ACPI_EVENT_RTC ,0 ); } +static void acpi_rtc_event_cleanup (void ) +{ +if (acpi_disabled) +return ; + +acpi_remove_fixed_event_handler (ACPI_EVENT_RTC , rtc_handler); +} +static void rtc_wake_on (struct device *dev) {acpi_clear_event (ACPI_EVENT_RTC );
@@ -890,6 +898,10 @@ static inline void acpi_rtc_event_setup(struct device *dev) { } +static inline void acpi_rtc_event_cleanup (void ) +{ +} +static inline void acpi_cmos_wake_setup (struct device *dev) { }
@@ -1143,6 +1155,9 @@ static void cmos_do_remove(struct device *dev)hpet_unregister_irq_handler (cmos_interrupt); } +if (!dev_get_platdata (dev)) +acpi_rtc_event_cleanup (); + cmos->rtc =NULL ; ports = cmos->iomem;
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 426/783 rtc: snvs: Allow a time difference on clock register read
In reply to Greg Kroah-HartmanFrom: Stefan Eichenberger <[email protected]>
[ Upstream commit 0462681e207ccc44778a77b3297af728b1cf5b9f ]
On an iMX6ULL the following message appears when a wakealarm is set:
echo 0 > /sys/class/rtc/rtc1/wakealarm
rtc rtc1: Timeout trying to get valid LPSRT Counter read
This does not always happen but is reproducible quite often (7 out of 10 times). The problem appears because the iMX6ULL is not able to read the registers within one 32kHz clock cycle which is the base clock of the RTC. Therefore, this patch allows a difference of up to 320 cycles (10ms). 10ms was chosen to be big enough even on systems with less cpu power (e.g. iMX6ULL). According to the reference manual a difference is fine:
- If the two consecutive reads are similar, the value is correct. The values have to be similar, not equal.
--- drivers/rtc/rtc-snvs.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-)
drivers/rtc/rtc-snvs.c +14 -2
@@ -32,6 +32,14 @@#define SNVS_LPPGDR_INIT 0x41736166#define CNTR_TO_SECS_SH 15 +/* The maximum RTC clock cycles that are allowed to pass between two +* consecutive clock counter register reads. If the values are corrupted a +* bigger difference is expected. The RTC frequency is 32kHz. With 320 cycles +* we end at 10ms which should be enough for most cases. If it once takes +* longer than expected we do a retry. +*/ +#define MAX_RTC_READ_DIFF_CYCLES 320 +struct snvs_rtc_data {struct rtc_device *rtc;struct regmap *regmap;
@@ -56,6 +64,7 @@ static u64 rtc_read_lpsrt(struct snvs_rtc_data *data)static u32 rtc_read_lp_counter (struct snvs_rtc_data *data) {u64 read1, read2; +s64 diff;unsigned int timeout =100 ;/* As expected, the registers might update between the read of the LSB
@@ -66,7 +75,8 @@ static u32 rtc_read_lp_counter(struct snvs_rtc_data *data)do { read2 = read1; read1 =rtc_read_lpsrt (data); - }while (read1 != read2 && --timeout); + diff = read1 - read2; + }while (((diff <0 ) || (diff >MAX_RTC_READ_DIFF_CYCLES )) && --timeout);if (!timeout)dev_err (&data->rtc->dev,"Timeout trying to get valid LPSRT Counter read\n" );
@@ -78,13 +88,15 @@ static u32 rtc_read_lp_counter(struct snvs_rtc_data *data)static int rtc_read_lp_counter_lsb (struct snvs_rtc_data *data,u32 *lsb) {u32 count1, count2; +s32 diff;unsigned int timeout =100 ;regmap_read (data->regmap, data->offset +SNVS_LPSRTCLR , &count1);do { count2 = count1;regmap_read (data->regmap, data->offset +SNVS_LPSRTCLR , &count1); - }while (count1 != count2 && --timeout); + diff = count1 - count2; + }while (((diff <0 ) || (diff >MAX_RTC_READ_DIFF_CYCLES )) && --timeout);if (!timeout) {dev_err (&data->rtc->dev,"Timeout trying to get valid LPSRT Counter read\n" );return -ETIMEDOUT ;
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 427/783 rtc: pcf85063: Fix reading alarm
In reply to Greg Kroah-HartmanFrom: Alexander Stein <[email protected]>
[ Upstream commit a6ceee26fd5ed9b5bd37322b1ca88e4548cee4a3 ]
If the alarms are disabled the topmost bit (AEN_*) is set in the alarm registers. This is also interpreted in BCD number leading to this warning:
rtc rtc0: invalid alarm value: 2022-09-21T80:80:80
Fix this by masking alarm enabling and reserved bits.
--- drivers/rtc/rtc-pcf85063.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/rtc/rtc-pcf85063.c +4 -4
@@ -167,10 +167,10 @@ static int pcf85063_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm)if (ret)return ret; - alrm->time.tm_sec =bcd2bin (buf[0 ]); - alrm->time.tm_min =bcd2bin (buf[1 ]); - alrm->time.tm_hour =bcd2bin (buf[2 ]); - alrm->time.tm_mday =bcd2bin (buf[3 ]); + alrm->time.tm_sec =bcd2bin (buf[0 ] &0x7f ); + alrm->time.tm_min =bcd2bin (buf[1 ] &0x7f ); + alrm->time.tm_hour =bcd2bin (buf[2 ] &0x3f ); + alrm->time.tm_mday =bcd2bin (buf[3 ] &0x3f ); ret =regmap_read (pcf85063->regmap,PCF85063_REG_CTRL2 , &val);if (ret)
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 428/783 iommu/amd: Fix pci device refcount leak in ppr_notifier()
In reply to Greg Kroah-HartmanFrom: Yang Yingliang <[email protected]>
[ Upstream commit 6cf0981c2233f97d56938d9d61845383d6eb227c ]
As comment of pci_get_domain_bus_and_slot() says, it returns a pci device with refcount increment, when finish using it, the caller must decrement the reference count by calling pci_dev_put(). So call it before returning from ppr_notifier() to avoid refcount leak.
--- drivers/iommu/amd/iommu_v2.c | 1 + 1 file changed, 1 insertion(+)
drivers/iommu/amd/iommu_v2.c +1 -0
@@ -587,6 +587,7 @@ static int ppr_notifier(struct notifier_block *nb, unsigned long e, void *data)put_device_state (dev_state); out: +pci_dev_put (pdev);return ret; }
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 429/783 iommu/fsl_pamu: Fix resource leak in fsl_pamu_probe()
In reply to Greg Kroah-HartmanFrom: Yuan Can <[email protected]>
[ Upstream commit 73f5fc5f884ad0c5f7d57f66303af64f9f002526 ]
The fsl_pamu_probe() returns directly when create_csd() failed, leaving irq and memories unreleased.
Fix by jumping to error if create_csd() returns error.
--- drivers/iommu/fsl_pamu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iommu/fsl_pamu.c +1 -1
@@ -1122,7 +1122,7 @@ static int fsl_pamu_probe(struct platform_device *pdev) ret =create_csd (ppaact_phys, mem_size, csd_port_id);if (ret) {dev_err (dev,"could not create coherence subdomain\n" ); -return ret; + goto error; } }
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 430/783 macintosh: fix possible memory leak in macio_add_one_device()
In reply to Greg Kroah-HartmanFrom: Yang Yingliang <[email protected]>
[ Upstream commit 5ca86eae55a2f006e6c1edd2029b2cacb6979515 ]
Afer commit 1fa5ae857bb1 ("driver core: get rid of struct device's bus_id string array"), the name of device is allocated dynamically. It needs to be freed when of_device_register() fails. Call put_device() to give up the reference that's taken in device_initialize(), so that it can be freed in kobject_cleanup() when the refcount hits 0.
macio device is freed in macio_release_dev(), so the kfree() can be removed.
--- drivers/macintosh/macio_asic.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/macintosh/macio_asic.c +1 -1
@@ -425,7 +425,7 @@ static struct macio_dev * macio_add_one_device(struct macio_chip *chip,if (of_device_register (&dev->ofdev) !=0 ) {printk (KERN_DEBUG "macio: device registration error for %s!\n" ,dev_name (&dev->ofdev.dev)); -kfree (dev); +put_device (&dev->ofdev.dev);return NULL ; }
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 431/783 macintosh/macio-adb: check the return value of ioremap()
In reply to Greg Kroah-HartmanFrom: Xie Shaowen <[email protected]>
[ Upstream commit dbaa3105736d4d73063ea0a3b01cd7fafce924e6 ]
The function ioremap() in macio_init() can fail, so its return value should be checked.
--- drivers/macintosh/macio-adb.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/macintosh/macio-adb.c +4 -0
@@ -106,6 +106,10 @@ int macio_init(void)return -ENXIO ; } adb =ioremap (r.start,sizeof (struct adb_regs )); +if (!adb) { +of_node_put (adbs); +return -ENOMEM ; + }out_8 (&adb->ctrl.r,0 );out_8 (&adb->intr.r,0 );
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 432/783 powerpc/52xx: Fix a resource leak in an error handling path
In reply to Greg Kroah-HartmanFrom: Christophe JAILLET <[email protected]>
[ Upstream commit 5836947613ef33d311b4eff6a32d019580a214f5 ]
The error handling path of mpc52xx_lpbfifo_probe() has a request_irq() that is not balanced by a corresponding free_irq().
Add the missing call, as already done in the remove function.
--- arch/powerpc/platforms/52xx/mpc52xx_lpbfifo.c | 1 + 1 file changed, 1 insertion(+)
arch/powerpc/platforms/52xx/mpc52xx_lpbfifo.c +1 -0
@@ -530,6 +530,7 @@ static int mpc52xx_lpbfifo_probe(struct platform_device *op) err_bcom_rx_irq:bcom_gen_bd_rx_release (lpbfifo.bcom_rx_task); err_bcom_rx: +free_irq (lpbfifo.irq, &lpbfifo); err_irq:iounmap (lpbfifo.regs); lpbfifo.regs =NULL ;
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 433/783 cxl: Fix refcount leak in cxl_calc_capp_routing
In reply to Greg Kroah-HartmanFrom: Miaoqian Lin <[email protected]>
[ Upstream commit 1d09697ff22908ae487fc8c4fbde1811732be523 ]
of_get_next_parent() returns a node pointer with refcount incremented, we should use of_node_put() on it when not need anymore. This function only calls of_node_put() in normal path, missing it in the error path.
Add missing of_node_put() to avoid refcount leak.
--- drivers/misc/cxl/pci.c | 1 + 1 file changed, 1 insertion(+)
drivers/misc/cxl/pci.c +1 -0
@@ -387,6 +387,7 @@ int cxl_calc_capp_routing(struct pci_dev *dev, u64 *chipid, rc =get_phb_index (np, phb_index);if (rc) {pr_err ("cxl: invalid phb index\n" ); +of_node_put (np);return rc; }
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 434/783 powerpc/xmon: Enable breakpoints on 8xx
In reply to Greg Kroah-HartmanFrom: Christophe Leroy <[email protected]>
[ Upstream commit 30662217885d7341161924acf1665924d7d37d64 ]
Since commit 4ad8622dc548 ("powerpc/8xx: Implement hw_breakpoint"), 8xx has breakpoints so there is no reason to opt breakpoint logic out of xmon for the 8xx.
Stable-dep-of: 1c4a4a4c8410 ("powerpc/xmon: Fix -Wswitch-unreachable warning in bpt_cmds")
--- arch/powerpc/xmon/xmon.c | 4 ---- 1 file changed, 4 deletions(-)
arch/powerpc/xmon/xmon.c +0 -4
@@ -1383,7 +1383,6 @@ static long check_bp_loc(unsigned long addr)return 1 ; } -#ifndef CONFIG_PPC_8xxstatic int find_free_data_bpt (void ) {int i;
@@ -1395,7 +1394,6 @@ static int find_free_data_bpt(void)printf ("Couldn't find free breakpoint register\n" );return -1 ; } -#endif static void print_data_bpts (void ) {
@@ -1435,7 +1433,6 @@ bpt_cmds(void) cmd =inchar ();switch (cmd) { -#ifndef CONFIG_PPC_8xxstatic const char badaddr[] ="Only kernel addresses are permitted for breakpoints\n" ;int mode;case 'd' :/* bd - hardware data breakpoint */
@@ -1497,7 +1494,6 @@ bpt_cmds(void)force_enable_xmon (); }break ; -#endif case 'c' :if (!scanhex (&a)) {
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 435/783 powerpc/xmon: Fix -Wswitch-unreachable warning in bpt_cmds
In reply to Greg Kroah-HartmanFrom: Gustavo A. R. Silva <[email protected]>
[ Upstream commit 1c4a4a4c8410be4a231a58b23e7a30923ff954ac ]
When building with automatic stack variable initialization, GCC 12 complains about variables defined outside of switch case statements. Move the variable into the case that uses it, which silences the warning:
arch/powerpc/xmon/xmon.c: In function ‘bpt_cmds’:arch/powerpc/xmon/xmon.c:1529:13: warning: statement will never be executed [-Wswitch-unreachable]
1529 | int mode;
| ^~~~--- arch/powerpc/xmon/xmon.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
arch/powerpc/xmon/xmon.c +4 -3
@@ -1433,9 +1433,9 @@ bpt_cmds(void) cmd =inchar ();switch (cmd) { -static const char badaddr[] ="Only kernel addresses are permitted for breakpoints\n" ; -int mode; -case 'd' :/* bd - hardware data breakpoint */ +case 'd' : {/* bd - hardware data breakpoint */ +static const char badaddr[] ="Only kernel addresses are permitted for breakpoints\n" ; +int mode;if (xmon_is_ro) {printf (xmon_ro_msg);break ;
@@ -1468,6 +1468,7 @@ bpt_cmds(void)force_enable_xmon ();break ; + }case 'i' :/* bi - hardware instr breakpoint */ if (xmon_is_ro) {
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 436/783 powerpc/xive: add missing iounmap() in error path in xive_spapr_populate_irq_data()
In reply to Greg Kroah-HartmanFrom: Yang Yingliang <[email protected]>
[ Upstream commit 8b49670f3bb3f10cd4d5a6dca17f5a31b173ecdc ]
If remapping 'data->trig_page' fails, the 'data->eoi_mmio' need be unmapped before returning from xive_spapr_populate_irq_data().
--- arch/powerpc/sysdev/xive/spapr.c | 1 + 1 file changed, 1 insertion(+)
arch/powerpc/sysdev/xive/spapr.c +1 -0
@@ -425,6 +425,7 @@ static int xive_spapr_populate_irq_data(u32 hw_irq, struct xive_irq_data *data) data->trig_mmio =ioremap (data->trig_page,1u << data->esb_shift);if (!data->trig_mmio) { +iounmap (data->eoi_mmio);pr_err ("Failed to map trigger page for irq 0x%x\n" , hw_irq);return -ENOMEM ; }
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 437/783 kbuild: remove unneeded mkdir for external modules_install
In reply to Greg Kroah-HartmanFrom: Masahiro Yamada <[email protected]>
[ Upstream commit 4b97ec0e9cfd5995f41b9726c88566a31f4625cc ]
scripts/Makefile.modinst creates directories as needed.
Stable-dep-of: c7b98de745cf ("phy: qcom-qmp-combo: fix runtime suspend")
--- Makefile | 2 -- 1 file changed, 2 deletions(-)
Makefile +0 -2
@@ -1746,10 +1746,8 @@ $(MODORDER): descend PHONY += modules_install modules_install: _emodinst_ _emodinst_post -install-dir := $(if $(INSTALL_MOD_DIR),$(INSTALL_MOD_DIR),extra) PHONY += _emodinst_ _emodinst_: - $(Q)mkdir -p $(MODLIB)/$(install-dir) $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modinst PHONY += _emodinst_post
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 438/783 kbuild: unify modules(_install) for in-tree and external modules
In reply to Greg Kroah-HartmanFrom: Masahiro Yamada <[email protected]>
[ Upstream commit 3e3005df73b535cb849cf4ec8075d6aa3c460f68 ]
If you attempt to build or install modules ('make modules(_install)' with CONFIG_MODULES disabled, you will get a clear error message, but nothing for external module builds.
Factor out the modules and modules_install rules into the common part, so you will get the same error message when you try to build external modules with CONFIG_MODULES=n.
Stable-dep-of: c7b98de745cf ("phy: qcom-qmp-combo: fix runtime suspend")
--- Makefile | 85 ++++++++++++++++++++++++-------------------------------- 1 file changed, 36 insertions(+), 49 deletions(-)
Makefile +36 -49
@@ -1425,7 +1425,6 @@ endif PHONY += modules modules: $(if $(KBUILD_BUILTIN),vmlinux) modules_check modules_prepare - $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost PHONY += modules_check modules_check: modules.order
@@ -1443,12 +1442,9 @@ PHONY += modules_prepare modules_prepare: prepare $(Q)$(MAKE) $(build)=scripts scripts/module.lds -# Target to install modules -PHONY += modules_install -modules_install: _modinst_ _modinst_post - -PHONY += _modinst_ -_modinst_: +modules_install: __modinst_pre +PHONY += __modinst_pre +__modinst_pre: @rm -rf $(MODLIB)/kernel @rm -f $(MODLIB)/source @mkdir -p $(MODLIB)/kernel
@@ -1460,14 +1456,6 @@ _modinst_: @sed 's:^:kernel/:' modules.order > $(MODLIB)/modules.order @cp -f modules.builtin $(MODLIB)/ @cp -f $(objtree)/modules.builtin.modinfo $(MODLIB)/ - $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modinst - -# This depmod is only for convenience to give the initial -# boot a modules.dep even before / is mounted read-write. However the -# boot script depmod is the master version. -PHONY += _modinst_post -_modinst_post: _modinst_ - $(call cmd,depmod) ifeq ($(CONFIG_MODULE_SIG), y) PHONY += modules_sign
@@ -1475,20 +1463,6 @@ modules_sign: $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modsign endif -else # CONFIG_MODULES - -# Modules not configured -# --------------------------------------------------------------------------- - -PHONY += modules modules_install -modules modules_install: - @echo >&2 - @echo >&2 "The present kernel configuration has modules disabled." - @echo >&2 "Type 'make config' and enable loadable module support." - @echo >&2 "Then build a kernel with module support enabled." - @echo >&2 - @exit 1 - endif # CONFIG_MODULES ###
@@ -1736,24 +1710,9 @@ KBUILD_BUILTIN := KBUILD_MODULES := 1 build-dirs := $(KBUILD_EXTMOD) -PHONY += modules -modules: $(MODORDER) - $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost - $(MODORDER): descend @: -PHONY += modules_install -modules_install: _emodinst_ _emodinst_post - -PHONY += _emodinst_ -_emodinst_: - $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modinst - -PHONY += _emodinst_post -_emodinst_post: _emodinst_ - $(call cmd,depmod) - compile_commands.json: $(extmod-prefix)compile_commands.json PHONY += compile_commands.json
@@ -1776,6 +1735,39 @@ PHONY += prepare modules_prepare endif # KBUILD_EXTMOD +# --------------------------------------------------------------------------- +# Modules + +PHONY += modules modules_install + +ifdef CONFIG_MODULES + +modules: $(MODORDER) + $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost + +quiet_cmd_depmod = DEPMOD $(KERNELRELEASE) + cmd_depmod = $(CONFIG_SHELL) $(srctree)/scripts/depmod.sh $(DEPMOD) \ + $(KERNELRELEASE) + +modules_install: + $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modinst + $(call cmd,depmod) + +else # CONFIG_MODULES + +# Modules not configured +# --------------------------------------------------------------------------- + +modules modules_install: + @echo >&2 '***' + @echo >&2 '*** The present kernel configuration has modules disabled.' + @echo >&2 '*** To use the module feature, please run "make menuconfig" etc.' + @echo >&2 '*** to enable CONFIG_MODULES.' + @echo >&2 '***' + @exit 1 + +endif # CONFIG_MODULES + # Single targets # --------------------------------------------------------------------------- # To build individual files in subdirectories, you can do like this:
@@ -1963,11 +1955,6 @@ tools/%: FORCE quiet_cmd_rmfiles = $(if $(wildcard $(rm-files)),CLEAN $(wildcard $(rm-files))) cmd_rmfiles = rm -rf $(rm-files) -# Run depmod only if we have System.map and depmod is executable -quiet_cmd_depmod = DEPMOD $(KERNELRELEASE) - cmd_depmod = $(CONFIG_SHELL) $(srctree)/scripts/depmod.sh $(DEPMOD) \ - $(KERNELRELEASE) - # read saved command lines for existing targets existing-targets := $(wildcard $(sort $(targets)))
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 439/783 kbuild: refactor single builds of *.ko
In reply to Greg Kroah-HartmanFrom: Masahiro Yamada <[email protected]>
[ Upstream commit f110e5a250e3c5db417e094b3dd86f1c135291ca ]
Remove the potentially invalid modules.order instead of using the temporary file.
Also, KBUILD_MODULES is don't care for single builds. No need to cancel it.
Stable-dep-of: c7b98de745cf ("phy: qcom-qmp-combo: fix runtime suspend")
--- Makefile | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-)
Makefile +4 -12
@@ -1766,6 +1766,8 @@ modules modules_install: @echo >&2 '***' @exit 1 +KBUILD_MODULES := + endif # CONFIG_MODULES # Single targets
@@ -1791,18 +1793,12 @@ $(single-ko): single_modpost $(single-no-ko): descend @: -ifeq ($(KBUILD_EXTMOD),) -# For the single build of in-tree modules, use a temporary file to avoid -# the situation of modules_install installing an invalid modules.order. -MODORDER := .modules.tmp -endif - +# Remove MODORDER when done because it is not the real one. PHONY += single_modpost single_modpost: $(single-no-ko) modules_prepare $(Q){ $(foreach m, $(single-ko), echo $(extmod-prefix)$m;) } > $(MODORDER) $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost - -KBUILD_MODULES := 1 + $(Q)rm -f $(MODORDER) export KBUILD_SINGLE_TARGETS := $(addprefix $(extmod-prefix), $(single-no-ko))
@@ -1812,10 +1808,6 @@ build-dirs := $(foreach d, $(build-dirs), \ endif -ifndef CONFIG_MODULES -KBUILD_MODULES := -endif - # Handle descending into subdirectories listed in $(build-dirs) # Preset locale variables to speed up the build process. Limit locale # tweaks to this spot to avoid wrong language settings when running
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 440/783 powerpc/perf: callchain validate kernel stack pointer bounds
In reply to Greg Kroah-HartmanFrom: Nicholas Piggin <[email protected]>
[ Upstream commit 32c5209214bd8d4f8c4e9d9b630ef4c671f58e79 ]
The interrupt frame detection and loads from the hypothetical pt_regs are not bounds-checked. The next-frame validation only bounds-checks STACK_FRAME_OVERHEAD, which does not include the pt_regs. Add another test for this.
The user could set r1 to be equal to the address matching the first interrupt frame - STACK_INT_FRAME_SIZE, which is in the previous page due to the kernel redzone, and induce the kernel to load the marker from there. Possibly this could cause a crash at least. If the user could induce the previous page to contain a valid marker, then it might be able to direct perf to read specific memory addresses in a way that could be transmitted back to the user in the perf data.
--- arch/powerpc/perf/callchain.c | 1 + 1 file changed, 1 insertion(+)
arch/powerpc/perf/callchain.c +1 -0
@@ -61,6 +61,7 @@ perf_callchain_kernel(struct perf_callchain_entry_ctx *entry, struct pt_regs *re next_sp = fp[0 ];if (next_sp == sp +STACK_INT_FRAME_SIZE && +validate_sp (sp, current,STACK_INT_FRAME_SIZE ) && fp[STACK_FRAME_MARKER ] ==STACK_FRAME_REGS_MARKER ) {/* * This looks like an interrupt frame for an
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 441/783 powerpc/83xx/mpc832x_rdb: call platform_device_put() in error case in of_fsl_spi_probe()
In reply to Greg Kroah-HartmanFrom: Yang Yingliang <[email protected]>
[ Upstream commit 4d0eea415216fe3791da2f65eb41399e70c7bedf ]
If platform_device_add() is not called or failed, it can not call platform_device_del() to clean up memory, it should call platform_device_put() in error case.
--- arch/powerpc/platforms/83xx/mpc832x_rdb.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/powerpc/platforms/83xx/mpc832x_rdb.c +1 -1
@@ -106,7 +106,7 @@ static int __init of_fsl_spi_probe(char *type, char *compatible, u32 sysclk, goto next; unreg: -platform_device_del (pdev); +platform_device_put (pdev); err:pr_err ("%pOF: registration failed\n" , np); next:
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 442/783 powerpc/hv-gpci: Fix hv_gpci event list
In reply to Greg Kroah-HartmanFrom: Kajol Jain <[email protected]>
[ Upstream commit 03f7c1d2a49acd30e38789cd809d3300721e9b0e ]
Based on getPerfCountInfo v1.018 documentation, some of the hv_gpci events were deprecated for platform firmware that supports counter_info_version 0x8 or above.
Fix the hv_gpci event list by adding a new attribute group called "hv_gpci_event_attrs_v6" and a "ENABLE_EVENTS_COUNTERINFO_V6" macro to enable these events for platform firmware
that supports counter_info_version 0x6 or below. And assigning the hv_gpci event list based on output counter info version of underlying plaform.
--- arch/powerpc/perf/hv-gpci-requests.h | 4 ++++ arch/powerpc/perf/hv-gpci.c | 33 +++++++++++++++++++++++++++- arch/powerpc/perf/hv-gpci.h | 1 + arch/powerpc/perf/req-gen/perf.h | 20 +++++++++++++++++ 4 files changed, 57 insertions(+), 1 deletion(-)
arch/powerpc/perf/hv-gpci-requests.h +4 -0
@@ -79,6 +79,7 @@ REQUEST(__field(0, 8, partition_id) )#include I (REQUEST_END ) +#ifdef ENABLE_EVENTS_COUNTERINFO_V6 /* * Not available for counter_info_version >= 0x8, use * run_instruction_cycles_by_partition(0x100) instead.
@@ -92,6 +93,7 @@ REQUEST(__field(0, 8, partition_id) __count(0x10, 8, cycles) )#include I (REQUEST_END ) +#endif #define REQUEST_NAME system_performance_capabilities#define REQUEST_NUM 0x40
@@ -103,6 +105,7 @@ REQUEST(__field(0, 1, perf_collect_privileged) )#include I (REQUEST_END ) +#ifdef ENABLE_EVENTS_COUNTERINFO_V6 #define REQUEST_NAME processor_bus_utilization_abc_links#define REQUEST_NUM 0x50#define REQUEST_IDX_KIND "hw_chip_id=?"
@@ -194,6 +197,7 @@ REQUEST(__field(0, 4, phys_processor_idx) __count(0x28, 8, instructions_completed) )#include I (REQUEST_END ) +#endif /* Processor_core_power_mode (0x95) skipped, no counters */ /* Affinity_domain_information_by_virtual_processor (0xA0) skipped,
arch/powerpc/perf/hv-gpci.c +32 -1
@@ -72,7 +72,7 @@ static struct attribute_group format_group = {static struct attribute_group event_group = { .name ="events" , - .attrs = hv_gpci_event_attrs, +/* .attrs is set in init */ };#define HV_CAPS_ATTR (_name, _format) \
@@ -330,6 +330,7 @@ static int hv_gpci_init(void)int r;unsigned long hret;struct hv_perf_caps caps; +struct hv_gpci_request_buffer *arg;hv_gpci_assert_offsets_correct ();
@@ -353,6 +354,36 @@ static int hv_gpci_init(void)/* sampling not supported */ h_gpci_pmu.capabilities |=PERF_PMU_CAP_NO_INTERRUPT ; + arg = (void *)get_cpu_var (hv_gpci_reqb); +memset (arg,0 ,HGPCI_REQ_BUFFER_SIZE ); + +/* +* hcall H_GET_PERF_COUNTER_INFO populates the output +* counter_info_version value based on the system hypervisor. +* Pass the counter request 0x10 corresponds to request type +* 'Dispatch_timebase_by_processor', to get the supported +* counter_info_version. +*/ + arg->params.counter_request =cpu_to_be32 (0x10 ); + + r =plpar_hcall_norets (H_GET_PERF_COUNTER_INFO , +virt_to_phys (arg),HGPCI_REQ_BUFFER_SIZE ); +if (r) { +pr_devel ("hcall failed, can't get supported counter_info_version: 0x%x\n" , r); + arg->params.counter_info_version_out =0x8 ; + } + +/* +* Use counter_info_version_out value to assign +* required hv-gpci event list. +*/ +if (arg->params.counter_info_version_out >=0x8 ) + event_group.attrs = hv_gpci_event_attrs; +else + event_group.attrs = hv_gpci_event_attrs_v6; + +put_cpu_var (hv_gpci_reqb); + r =perf_pmu_register (&h_gpci_pmu, h_gpci_pmu.name,-1 );if (r)return r;
arch/powerpc/perf/hv-gpci.h +1 -0
@@ -26,6 +26,7 @@ enum {#define REQUEST_FILE "../hv-gpci-requests.h"#define NAME_LOWER hv_gpci#define NAME_UPPER HV_GPCI +#define ENABLE_EVENTS_COUNTERINFO_V6 #include "req-gen/perf.h" #undef REQUEST_FILE#undef NAME_LOWER
arch/powerpc/perf/req-gen/perf.h +20 -0
@@ -139,6 +139,26 @@ PMU_EVENT_ATTR_STRING( \#define REQUEST_ (r_name, r_value, r_idx_1, r_fields) \ r_fields +/* Generate event list for platforms with counter_info_version 0x6 or below */ +static __maybe_unused struct attribute *hv_gpci_event_attrs_v6[] = { +#include REQUEST_FILE +NULL +}; + +/* +* Based on getPerfCountInfo v1.018 documentation, some of the hv-gpci +* events were deprecated for platform firmware that supports +* counter_info_version 0x8 or above. +* Those deprecated events are still part of platform firmware that +* support counter_info_version 0x6 and below. As per the getPerfCountInfo +* v1.018 documentation there is no counter_info_version 0x7. +* Undefining macro ENABLE_EVENTS_COUNTERINFO_V6, to disable the addition of +* deprecated events in "hv_gpci_event_attrs" attribute group, for platforms +* that supports counter_info_version 0x8 or above. +*/ +#undef ENABLE_EVENTS_COUNTERINFO_V6 + +/* Generate event list for platforms with counter_info_version 0x8 or above*/ static __maybe_unused struct attribute *hv_gpci_event_attrs[] = { #include REQUEST_FILE NULL
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 443/783 selftests/powerpc: Fix resource leaks
In reply to Greg Kroah-HartmanFrom: Miaoqian Lin <[email protected]>
[ Upstream commit 8f4ab7da904ab7027ccd43ddb4f0094e932a5877 ]
In check_all_cpu_dscr_defaults, opendir() opens the directory stream. Add missing closedir() in the error path to release it.
In check_cpu_dscr_default, open() creates an open file descriptor. Add missing close() in the error path to release it.
--- tools/testing/selftests/powerpc/dscr/dscr_sysfs_test.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
tools/testing/selftests/powerpc/dscr/dscr_sysfs_test.c +4 -1
@@ -24,6 +24,7 @@ static int check_cpu_dscr_default(char *file, unsigned long val) rc =read (fd, buf,sizeof (buf));if (rc ==-1 ) {perror ("read() failed" ); +close (fd);return 1 ; }close (fd);
@@ -65,8 +66,10 @@ static int check_all_cpu_dscr_defaults(unsigned long val)if (access (file,F_OK ))continue ; -if (check_cpu_dscr_default (file, val)) +if (check_cpu_dscr_default (file, val)) { +closedir (sysfs);return 1 ; + } }closedir (sysfs);return 0 ;
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 444/783 iommu/sun50i: Remove IOMMU_DOMAIN_IDENTITY
In reply to Greg Kroah-HartmanFrom: Jason Gunthorpe <[email protected]>
[ Upstream commit ef5bb8e7a7127218f826b9ccdf7508e7a339f4c2 ]
This driver treats IOMMU_DOMAIN_IDENTITY the same as UNMANAGED, which cannot possibly be correct.
UNMANAGED domains are required to start out blocking all DMAs. This seems to be what this driver does as it allocates a first level 'dt' for the IO page table that is 0 filled.
Thus UNMANAGED looks like a working IO page table, and so IDENTITY must be a mistake. Remove it.
--- drivers/iommu/sun50i-iommu.c | 1 - 1 file changed, 1 deletion(-)
drivers/iommu/sun50i-iommu.c +0 -1
@@ -603,7 +603,6 @@ static struct iommu_domain *sun50i_iommu_domain_alloc(unsigned type)struct sun50i_iommu_domain *sun50i_domain;if (type !=IOMMU_DOMAIN_DMA && - type !=IOMMU_DOMAIN_IDENTITY && type !=IOMMU_DOMAIN_UNMANAGED )return NULL ;
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 445/783 pwm: sifive: Call pwm_sifive_update_clock() while mutex is held
In reply to Greg Kroah-HartmanFrom: Uwe Kleine-König <[email protected]>
[ Upstream commit 45558b3abb87eeb2cedb8a59cb2699c120b5102a ]
As was documented in commit 0f02f491b786 ("pwm: sifive: Reduce time the controller lock is held") a caller of pwm_sifive_update_clock() must hold the mutex. So fix pwm_sifive_clock_notifier() to grab the lock.
While this necessity was only documented later, the race exists since the driver was introduced.
--- drivers/pwm/pwm-sifive.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/pwm/pwm-sifive.c +4 -1
@@ -217,8 +217,11 @@ static int pwm_sifive_clock_notifier(struct notifier_block *nb,struct pwm_sifive_ddata *ddata = container_of(nb, struct pwm_sifive_ddata, notifier); -if (event ==POST_RATE_CHANGE ) +if (event ==POST_RATE_CHANGE ) { +mutex_lock (&ddata->lock);pwm_sifive_update_clock (ddata, ndata->new_rate); +mutex_unlock (&ddata->lock); + }return NOTIFY_OK ; }
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 446/783 remoteproc: sysmon: fix memory leak in qcom_add_sysmon_subdev()
In reply to Greg Kroah-HartmanFrom: Gaosheng Cui <[email protected]>
[ Upstream commit e01ce676aaef3b13d02343d7e70f9637d93a3367 ]
The kfree() should be called when of_irq_get_byname() fails or devm_request_threaded_irq() fails in qcom_add_sysmon_subdev(), otherwise there will be a memory leak, so add kfree() to fix it.
--- drivers/remoteproc/qcom_sysmon.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/remoteproc/qcom_sysmon.c +4 -1
@@ -625,7 +625,9 @@ struct qcom_sysmon *qcom_add_sysmon_subdev(struct rproc *rproc,if (sysmon->shutdown_irq != -ENODATA ) {dev_err (sysmon->dev,"failed to retrieve shutdown-ack IRQ\n" ); -return ERR_PTR (sysmon->shutdown_irq); + ret = sysmon->shutdown_irq; +kfree (sysmon); +return ERR_PTR (ret); } }else { ret = devm_request_threaded_irq(sysmon->dev,
@@ -636,6 +638,7 @@ struct qcom_sysmon *qcom_add_sysmon_subdev(struct rproc *rproc,if (ret) {dev_err (sysmon->dev,"failed to acquire shutdown-ack IRQ\n" ); +kfree (sysmon);return ERR_PTR (ret); } }
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 447/783 remoteproc: qcom_q6v5_pas: disable wakeup on probe fail or remove
In reply to Greg Kroah-HartmanFrom: Luca Weiss <[email protected]>
[ Upstream commit 9a70551996e699fda262e8d54bbd41739d7aad6d ]
Leaving wakeup enabled during probe fail (-EPROBE_DEFER) or remove makes the subsequent probe fail.
[ 3.749454] remoteproc remoteproc0: releasing 3000000.remoteproc [ 3.752949] qcom_q6v5_pas: probe of 3000000.remoteproc failed with error -17 [ 3.878935] remoteproc remoteproc0: releasing 4080000.remoteproc [ 3.887602] qcom_q6v5_pas: probe of 4080000.remoteproc failed with error -17 [ 4.319552] remoteproc remoteproc0: releasing 8300000.remoteproc [ 4.332716] qcom_q6v5_pas: probe of 8300000.remoteproc failed with error -17
Fix this by disabling wakeup in both cases so the driver can properly probe on the next try.
--- drivers/remoteproc/qcom_q6v5_pas.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/remoteproc/qcom_q6v5_pas.c +2 -0
@@ -472,6 +472,7 @@ static int adsp_probe(struct platform_device *pdev) detach_active_pds:adsp_pds_detach (adsp, adsp->active_pds, adsp->active_pd_count); free_rproc: +device_init_wakeup (adsp->dev, false);rproc_free (rproc);return ret;
@@ -487,6 +488,7 @@ static int adsp_remove(struct platform_device *pdev)qcom_remove_sysmon_subdev (adsp->sysmon);qcom_remove_smd_subdev (adsp->rproc, &adsp->smd_subdev);qcom_remove_ssr_subdev (adsp->rproc, &adsp->ssr_subdev); +device_init_wakeup (adsp->dev, false);rproc_free (adsp->rproc);return 0 ;
Signature · 1 line
2.35.1